Reuse data type defined in another xml schema file : Salami Slice « XML Schema « XML






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>

 








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
7.Schema for XSchema elements