Mega Code Archive

 
Categories / XML / XML Schema
 

Reuse data type defined

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:element name="library">     <xs:complexType>       <xs:sequence>         <xs:element ref="DVD" minOccurs="0" maxOccurs="unbounded"/>       </xs:sequence>     </xs:complexType>   </xs:element>   <xs:element name="DVD">     <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:schema>