Click here to Skip to main content
15,843,145 members
Please Sign up or sign in to vote.
1.67/5 (2 votes)
See more:
I want to compare the schema structure of 2 xmls.For that purpose I created xsd from one xml and then comparig that xsd (schema structure) with another xml...so that I can know whether both xml have same structure or not.

following is xml

XML
<?xml version="1.0"?>
<bookstore xmlns="generic">
   <book genre="autobiography">
       <title>The Autobiography of Benjamin Franklin</title>
       <author>
           <first-name>Ben</first-name>
           <last-name>Franklin</last-name>
       </author>
       <price>89.88</price>
   </book>
   <book genre="novel">
       <title>The Confidence Man</title>
       <author>
           <first-name>John</first-name>
           <last-name>Melville</last-name>
       </author>
       <price>11.99</price>
   </book>
</bookstore>


generated xsd is
XML
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="bookstore" targetNamespace="generic" xmlns:mstns="generic" xmlns="generic" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified">
  <xs:element name="bookstore" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="book">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="title" type="xs:string" minOccurs="0" msdata:Ordinal="0" />
              <xs:element name="price" type="xs:string" minOccurs="0" msdata:Ordinal="2" />
              <xs:element name="author" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="first-name" type="xs:string" minOccurs="0" />
                    <xs:element name="last-name" type="xs:string" minOccurs="0" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="genre" form="unqualified" type="xs:string" />
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>


when comparing xml and xsd both,error comes

but when i use following xsd
HTML
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="generic" elementFormDefault="qualified" targetNamespace="generic"> 
   <xsd:element name="bookstore" type="bookstoreType"/> 
   <xsd:complexType name="bookstoreType"> 
       <xsd:sequence maxOccurs="unbounded"> 
           <xsd:element name="book" type="bookType"/> 
       </xsd:sequence> 
   </xsd:complexType> 
   <xsd:complexType name="bookType"> 
       <xsd:sequence> 
           <xsd:element name="title" type="xsd:string"/> 
           <xsd:element name="author" type="authorName"/> 
           <xsd:element name="price" type="xsd:decimal"/> 
       </xsd:sequence> 
       <xsd:attribute name="genre" type="xsd:string"/> 
   </xsd:complexType> 
   <xsd:complexType name="authorName"> 
       <xsd:sequence> 
           <xsd:element name="first-name" type="xsd:string"/> 
           <xsd:element name="last-name" type="xsd:string"/> 
       </xsd:sequence> 
   </xsd:complexType> 
</xsd:schema> 


comparison is successful

pls help

hight appreciable
Posted
Updated 2-Apr-14 19:28pm
v2
Comments
Sergey Alexandrovich Kryukov 2-Apr-14 16:05pm    
What does it mean "comparing xml and xsd"? :-)
Automatically generated XSD (based on a single sample) cannot be of the best on. It only guarantees that it conforms to one particular XML and some narrow class of ones similar to that one. More loose XSD is more likely to cover different variants of XMLs, but is less valuable. Good XSDs are written out of general data model (whatever it is, can be just a mental model).
—SA
shivani 2013 3-Apr-14 0:27am    
I just want to compare the schema structure of 2 xml.For that purpose I created xsd from one xml and then comparig that xsd (schema structure) with another xml...so that I can know whether both xml have same structure or not
shivani 2013 3-Apr-14 3:48am    
I got cause..order of elements in xml and xsd are different but now issue is how to ignore the order

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