XML schema for list of tags with identical structure : element « XML Schema « XML






XML schema for list of tags with identical structure


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 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>

 








Related examples in the same category

1.Schema for elements with inner elements and attribute
2.Element with anonymous complexType and sequence
3.Reference element as type
4.element with maxOccurs="unbounded"
5.Element with fixed value
6.Reference element with fixed value
7.Define element type outside
8.Element with anonymous simpleType
9.Reference element based on simpleType
10.Element referencing another element