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:xmln s:COMMONCENSUS: CommonFormat:IM Schema'> 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:xmln s:COMMONCENSUS: CommonFormat:IM Schema" xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance" exportType="T">
<application guid="{9A44D2FF-90EB-45BE-BC88-CF2107B2CA4C}" xmlns="urn:xmln s:COMMONCENSUS: CommonFormat:IM Schema">
-----
</application>
</applications>
xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="urn:xmln s:COMMONCENSUS: CommonFormat:IM Schema" xmlns:NS="urn:x mlns:COMMONCENS US:CommonFormat :IMSchema" targetNamespace ="urn:xmlns:COM MONCENSUS:Commo nFormat:IMSchem a" elementFormDefa ult="qualified" >
<xs:element name="applicati ons">
<xs:complexType >
<xs:sequence>
<xs:element name="applicati on" type="Applicati onType" minOccurs="0" maxOccurs="unbo unded">
<xs:key name="personKey ">
<xs:selector xpath="persons/person" />
<xs:field xpath="id" />
</xs:key>
<xs:keyref name="applicant KeyRef" refer="personKe y">
<xs:selector xpath="applican tID" />
<xs:field xpath="." />
</xs:keyref>
<xs:keyref name="insuredKe yRef" refer="personKe y">
<xs:selector xpath="coverage s/coverage/insuredID" />
<xs:field xpath="." />
</xs:keyref>
</xs:element>
</xs:sequence>
<xs:attribute name="exportTyp e" type="ExportTyp e" />
</xs:complexType>
</xs:element>
-----
</xs:schema>
Code:
// Read the xml file
TextReader reader = new StreamReader("C :\\CommonSensus Xml\\Policy_876 54321_210_Dion-Paul_WSA.xml");
//Application Type
XmlSerializer serializer = new XmlSerializer(t ypeof(Applicati onType));
ApplicationType appType = (ApplicationTyp e)serializer.De serialize(reade r);
Exception:There is an error in XML document (2, 2).
Inner Exception: <applications xmlns='urn:xmln s:COMMONCENSUS: CommonFormat:IM Schema'> 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:xmln s:COMMONCENSUS: CommonFormat:IM Schema" xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance" exportType="T">
<application guid="{9A44D2FF-90EB-45BE-BC88-CF2107B2CA4C}" xmlns="urn:xmln s:COMMONCENSUS: CommonFormat:IM Schema">
-----
</application>
</applications>
xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="urn:xmln s:COMMONCENSUS: CommonFormat:IM Schema" xmlns:NS="urn:x mlns:COMMONCENS US:CommonFormat :IMSchema" targetNamespace ="urn:xmlns:COM MONCENSUS:Commo nFormat:IMSchem a" elementFormDefa ult="qualified" >
<xs:element name="applicati ons">
<xs:complexType >
<xs:sequence>
<xs:element name="applicati on" type="Applicati onType" minOccurs="0" maxOccurs="unbo unded">
<xs:key name="personKey ">
<xs:selector xpath="persons/person" />
<xs:field xpath="id" />
</xs:key>
<xs:keyref name="applicant KeyRef" refer="personKe y">
<xs:selector xpath="applican tID" />
<xs:field xpath="." />
</xs:keyref>
<xs:keyref name="insuredKe yRef" refer="personKe y">
<xs:selector xpath="coverage s/coverage/insuredID" />
<xs:field xpath="." />
</xs:keyref>
</xs:element>
</xs:sequence>
<xs:attribute name="exportTyp e" type="ExportTyp e" />
</xs:complexType>
</xs:element>
-----
</xs:schema>
Code:
// Read the xml file
TextReader reader = new StreamReader("C :\\CommonSensus Xml\\Policy_876 54321_210_Dion-Paul_WSA.xml");
//Application Type
XmlSerializer serializer = new XmlSerializer(t ypeof(Applicati onType));
ApplicationType appType = (ApplicationTyp e)serializer.De serialize(reade r);
Comment