<?xml version="1.0" encoding="utf-16"?>
<ns1:Root xmlns:ns1="http://someWebsite.com/foldername/schemaFile" xmlns:ns2="http://someWebsite.com/foldername/BaseschemaFile" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://someWebsite.com/foldername/schemaFile file:/C:/xsd/schemaFile.xsd">
<ns1:Root1 val1="abcd" val2="2008-05-04T18:13:51.0Z" />
<ns1:Root2 r2val1="16" r2val2="1234" r2valcompanyName="Jing Company" r2valcontactName="Jinga" r2valcontactPhone="123-456-7890" r2val3status="A">
<ns1:Address streetAddress1="jing jung " streetAddress2="juck" city="jinjunakka" state="ji" zipCode="12345" />
</ns1:Root2>
</ns1:Root>
If you see this XML ,You can see different things like ns1,url for Webiste and Schema file location.
If you try to deserialize using normal deserialization method you will get many errors like
"
Use name Space in all the Attribute and Element declaration you can get that from xsd file
[Serializable()]
[XmlRoot("Root", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public sealed class RootClass
{
[XmlElement("Root1", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public Root1Class Root1 = new Root1Class();
[XmlElement("Root2", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public Root2Class Root2 = new Root2Class();
}
[Serializable()]
[XmlRoot("Root1", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public sealed class Root1
{
[XmlAttribute("val1", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public string val1 = string.Empty;
[XmlAttribute("val2", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public string val2 = string.Empty;
}
[Serializable()]
[XmlRoot("Root2", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public sealed class Root2
{
[XmlAttribute("r2val1", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public string r2val1 = string.Empty;
[XmlAttribute("r2val2", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public string r2val2 = string.Empty;
[XmlAttribute("r2valcompanyName", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public string r2valcompanyName = string.Empty;
[XmlAttribute("r2valcontactPhone", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public string r2valcontactPhone = string.Empty;
[XmlAttribute("r2val3status", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public string r2val3status = string.Empty;
//Check here
[XmlElement("Address", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public Address address = new Address();
}
[Serializable()]
[XmlRoot("Address", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public sealed class Address
{
[XmlAttribute("streetAddress1", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public string streetAddress1 = string.Empty;
[XmlAttribute("streetAddress2", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public string streetAddress2 = string.Empty;
[XmlAttribute("city", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public string city = string.Empty;
[XmlAttribute("state", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public string state = string.Empty;
[XmlAttribute("zipCode", Namespace = "http://someWebsite.com/foldername/schemaFile")]
public string zipCode = string.Empty;
}
No comments:
Post a Comment