I'm using XmlSerializer to deserialize an xml into classes. The error I recieve is:
Exception:There is an error in XML document (2, 2).
Inner Exception: <applications xmlns='urn:xmlns:COMMONCENSUS:CommonFormat:IMSchem a'> was not expected.
I've read numerous threads on this but none seem to help with this particular issue. I've included the xml, and the Schema file below as well as the code. First post also, so I'm not sure how to add the code in a more readable way. Thanks in advance.
xml:
<?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>
xsd:
<?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);