I'm using XmlSerializer in C# to deserialize an xml into classes. First I generated the code from the schema using xsd.exe The error I recieve is:
Exception:There is an error in XML document (2, 2).
Inner Exception: <applications xmlns='urn:xmln s:COMMONCENSUS: CommonFormat:IM Schem a'> was not expected.
I've read numerous threads and realize it is a namespace issue, but none seem to help with this particular problem. I've included the xml, and the Schema file below as well as the code. Thanks in advance.
xml:
xsd:
Code:
Exception:There is an error in XML document (2, 2).
Inner Exception: <applications xmlns='urn:xmln s:COMMONCENSUS: CommonFormat:IM Schem a'> was not expected.
I've read numerous threads and realize it is a namespace issue, but none seem to help with this particular problem. I've included the xml, and the Schema file below as well as the code. Thanks in advance.
xml:
Code:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<applications xmlns="urn:xmlns:COMMONCENSUS:CommonFormat:IMSchem a" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exportType="T">
<application guid="{9A44D2FF-90EB-45BE-BC88-CF2107B2CA4C}" xmlns="urn:xmlns:COMMONCENSUS:CommonFormat:IMSchem a">
-----
</application>
</applications>
Code:
<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="urn:xmlns:COMMONCENSUS:CommonFormat:IMSchem a" xmlns:NS="urn:xmlns:COMMONCENSUS:CommonFormat:IMSc hema" targetNamespace="urn:xmlns:COMMONCENSUS:CommonForm at:IMSchema" elementFormDefault="qualified"> <xs:element name="applications"> <xs:complexType> <xs:sequence> <xs:element name="application" type="ApplicationType" minOccurs="0" maxOccurs="unbounded"> <xs:key name="personKey"> <xs:selector xpath="persons/person" /> <xs:field xpath="id" /> </xs:key> <xs:keyref name="applicantKeyRef" refer="personKey"> <xs:selector xpath="applicantID" /> <xs:field xpath="." /> </xs:keyref> <xs:keyref name="insuredKeyRef" refer="personKey"> <xs:selector xpath="coverages/coverage/insuredID" /> <xs:field xpath="." /> </xs:keyref> </xs:element> </xs:sequence> <xs:attribute name="exportType" type="ExportType" /> </xs:complexType> </xs:element> ----- </xs:schema>
Code:
// Read the xml file
TextReader reader = new StreamReader("C:\\CommonSensusXml\\Policy_87654321 _210_Dion-Paul_WSA.xml");
//Application Type
XmlSerializer serializer = new XmlSerializer(typeof(ApplicationType));
ApplicationType appType = (ApplicationType)serializer.Deserialize(reader);
Comment