Mega Code Archive

 
Categories / XML / XML Schema
 

Reuse data type defined in another xml schema file

File: Data.xml <?xml version="1.0" encoding="UTF-8"?> <library>   <DVD id="1">     <title>title 1</title>     <format>Movie</format>     <genre>Classic</genre>   </DVD>   <DVD id="2">     <title>Contact</title>     <format>Movie</format>     <genre>Science fiction</genre>   </DVD> </library> File: Schema.xsd <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:include schemaLocation="customDataType.xsd"/>   <xs:element name="library">     <xs:complexType>       <xs:sequence>         <xs:element name="DVD" minOccurs="0" maxOccurs="unbounded">           <xs:complexType>             <xs:sequence>               <xs:element name="title" type="xs:string"/>               <xs:element name="format" type="xs:string"/>               <xs:element name="genre" type="xs:string"/>             </xs:sequence>             <xs:attribute name="id" type="xs:integer" use="required"/>           </xs:complexType>         </xs:element>       </xs:sequence>     </xs:complexType>   </xs:element> </xs:schema> File: customDataType.xsd <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">   <xs:simpleType name="YesNoType">     <xs:restriction base="xs:string">       <xs:enumeration value="no"/>       <xs:enumeration value="yes"/>     </xs:restriction>   </xs:simpleType> </xs:schema>