Validating an XML file using XSD Schema files. (XML Structure)

LucyD1981

New Member
For an XML document that looks like this, \[code\]<Products> <productTypes> <productType name="BigOranges"> <product> <name>BigOrange1</name> <quatity>25</quatity> </product> <product> <name>BigOrange2</name> <quatity>55</quatity> </product> </productType> <productType name="BigApples"> <product> <name>BigApples1</name> <quatity>25</quatity> </product> <product> <name>BigApples2</name> <quatity>55</quatity> </product> </productType> </productTypes></Products>\[/code\]I tried to auto-generate the XSD file to see an example and this is what was generated. \[code\]<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:simpleType name="T_quatity"> <xs:restriction base="xs:byte"> <xs:enumeration value="http://stackoverflow.com/questions/10819377/25"/> <xs:enumeration value="http://stackoverflow.com/questions/10819377/55"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="T_name"> <xs:restriction base="xs:string"> <xs:enumeration value="http://stackoverflow.com/questions/10819377/BigApples1"/> <xs:enumeration value="http://stackoverflow.com/questions/10819377/BigApples2"/> <xs:enumeration value="http://stackoverflow.com/questions/10819377/BigOrange1"/> <xs:enumeration value="http://stackoverflow.com/questions/10819377/BigOrange2"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="AT_1"> <xs:restriction base="xs:string"> <xs:enumeration value="http://stackoverflow.com/questions/10819377/BigApples"/> <xs:enumeration value="http://stackoverflow.com/questions/10819377/BigOranges"/> </xs:restriction> </xs:simpleType> <xs:complexType name="T_productTypes"> <xs:sequence> <xs:element ref="productType" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name="T_productType"> <xs:sequence> <xs:element ref="product" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute ref="name" use="required"/> </xs:complexType> <xs:complexType name="T_product"> <xs:sequence> <xs:element ref="name"/> <xs:element ref="quatity"/> </xs:sequence> </xs:complexType> <xs:complexType name="T_Products"> <xs:sequence> <xs:element ref="productTypes"/> </xs:sequence> </xs:complexType> <xs:attribute name="name" type="AT_1"/> <xs:element name="quatity" type="T_quatity"/> <xs:element name="productTypes" type="T_productTypes"/> <xs:element name="productType" type="T_productType"/> <xs:element name="product" type="T_product"/> <xs:element name="name" type="T_name"/> <xs:element name="Products" type="T_Products"/></xs:schema>\[/code\]Looking at the above, i can see that what is happening is that they types are defined and these are then used later when the elements are defined. What i don't understand though is that the elements are defined one after the other and do not follow the structure of the XML message. If this schema will be used to validate the XML document, how will the structure of the XML file be validated? For example using the above schema, how does it know that the productTypes element is an inner tag for the productType tag?
 
Back
Top