Click here to Skip to main content
15,887,404 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
In my application i am generating xsd from xml file.But i got error during Deserialize that xsd and displaying error message like "There is an error in XML document (2, 2)." If you have any solution on this problem then please let us know.

Sample xsd:

XML
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
        targetNamespace="http://www.w3schools.com" elementFormDefault="qualified">
  <xs:element name="CASES" >
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="CASE">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="RECEIVED_DATE" type="xs:string" minOccurs="0" />
              <xs:element name="DIVISION_CODE" type="xs:string" minOccurs="0" />
              <xs:element name="LOCATION_CODE" type="xs:string" minOccurs="0" />
              <xs:element name="LOCATION_NAME" type="xs:string" minOccurs="0" />
              <xs:element name="LOCATION_ADDRESS1" type="xs:string" minOccurs="0" />
              <xs:element name="PARTIES" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="PARTY" minOccurs="0" maxOccurs="unbounded">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="FIRST_NAME" type="xs:string" minOccurs="0" msdata:Ordinal="0" />
                          <xs:element name="LAST_NAME" type="xs:string" minOccurs="0" msdata:Ordinal="1" />
                        </xs:sequence>
                        <xs:attribute name="TYPE_DESCRIPTION" type="xs:string" />
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>


Sample code:
C#
StreamReader reader = new StreamReader(_myXmlPath);
XmlSerializer serializer = new XmlSerializer(typeof(CASES));
CASES myCases = (CASES)serializer.Deserialize(reader);   //error occure

Thanks In Advanced.
Posted
Updated 31-Jan-12 21:03pm
v3
Comments
Sergey Alexandrovich Kryukov 1-Feb-12 2:11am    
Fix the error in XML document. This is all one can advise based on this information.
--SA
OriginalGriff 1-Feb-12 2:23am    
Without the relevant code fragments (serialize and deserialize, and possibly the relevant bits of the xml file) we can't answre that.
What you have done so far is phoned the garage, said "my car is broken" and put the phone down. Do you expect them to fix it for you while you have a cup of tea? They don't know which car, where it is, who you are, or what is wrong with it.
Use the "Improve question" widget to edit your question and provide better information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900