Reuse data type defined : Salami Slice « XML Schema « XML






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>

 








Related examples in the same category

1.Salami Slice Design
2.Reuse complex type
3.Global attibute definitions
4.Ref and Salami Slice
5.different types with the same name
6.Reuse data type defined in another xml schema file
7.Schema for XSchema elements