xml serialisation
-
Hi... I need to create an XML file from an object, and I have to obtain the the following root element:
<declaresalary>
xmlns:st="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclarationServiceTypes"
xmlns:ct="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclarationContainer"
xmlns:sd="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclaration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
ct:requestcontext
...My problem is that I can't figure out how to set all those xmlns attributes. Can somebody give me an hint please?
Life is not short... the problem is only how you organize yourself
-
Hi... I need to create an XML file from an object, and I have to obtain the the following root element:
<declaresalary>
xmlns:st="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclarationServiceTypes"
xmlns:ct="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclarationContainer"
xmlns:sd="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclaration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
ct:requestcontext
...My problem is that I can't figure out how to set all those xmlns attributes. Can somebody give me an hint please?
Life is not short... the problem is only how you organize yourself
-
Hi... I need to create an XML file from an object, and I have to obtain the the following root element:
<declaresalary>
xmlns:st="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclarationServiceTypes"
xmlns:ct="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclarationContainer"
xmlns:sd="http://www.swissdec.ch/schema/sd/20051002/SalaryDeclaration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
ct:requestcontext
...My problem is that I can't figure out how to set all those xmlns attributes. Can somebody give me an hint please?
Life is not short... the problem is only how you organize yourself
the right use of XmlSerializerNamespaces is
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add("ct", "http://www.swissdec.ch/schema/sd/20051002/SalaryDeclarationContainer");
namespaces.Add("sd", "http://www.swissdec.ch/schema/sd/20051002/SalaryDeclaration");
namespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");System.IO.File.Delete(pPathToGenerate);
fs = new System.IO.FileStream(pPathToGenerate, System.IO.FileMode.Create);
writer = new System.Xml.Serialization.XmlSerializer(typeof(XmlSerializatorItems.DeclareSalary));
writer.Serialize(fs, oDeclare, namespaces);
fs.Close();In the object to serialize you have to specify the namespace for each field.
Life is not short... the problem is only how you organize yourself