Workshops --> XML --> Demo --> schema15.html
SLIS@IU logo

L595 XML@IU logo

Creating Schemas

Complex types

Declaring complex type elements that only contain text

Note that a text-only complex type can have attributes

The generic form is:

<xsd:element name="element_name">
    <xsd:complexType>
        <xsd:simpleContent>
            <xsd:extension base="simpleType">
                     <xsd:attribute name="name" type="someValue" />
              </xsd:extension>
          </xsd:simpleContent>
    </xsd:complexType>
</xsd:element>

This is a valid element

<xsd:element name="alien_probe">
    <xsd:complexType>
        <xsd:simpleContent>
            <xsd:extension base="simpleType">
                     <xsd:attribute name="size" type="xsd:integer" />
              </xsd:extension>
          </xsd:simpleContent>
    </xsd:complexType>
</xsd:element>

This is how it would look in the XML file

<alien_probe size="120 cm">metallic and electrified<alien_probe>

This complex type element can also be defined as a custom complex type

The generic form is:

<xsd:complexType name="nameType">
    <xsd:simpleContent>
        <xsd:extension base="simpleType">
             <xsd:attribute name="name" type="someValue" />
          </xsd:extension>
      </xsd:simpleContent>
</xsd:complexType>

This is a valid element:

<xsd:complexType name="alien_probeType" minOccurs="2">
    <xsd:simpleContent>
        <xsd:extension base="xsd:string">
             <xsd:attribute name="size" type="xsd:string" />
          </xsd:extension>
     </xsd:simpleContent>
</xsd:complexType>

This is how the element is called in the schema

<xsd:element name="alien_probe" type="alien_probeType">

This is how the element appears in the XML document

<alien_probe size="14cm">Ouch!</alien_probe>

Declaring empty complex type elements

Note that a empty complex type can have attributes

The generic form is:

<xsd:complexType name="name">
    <xsd:complexContent>
        <xsd:extension base="xsd:anyType">
            < xsd:attribute name="name" type="someValue" />
         </xsd:extension>
     </xsd:complexContent>
</xsd:complexType>

This is a valid element:

<xsd:complexType name="alien_probeType">
    <xsd:complexContent>
        <xsd:extension base="xsd:anyType">
            < xsd:attribute name="size" type="xsd:string" />
         </xsd:extension>
     </xsd:complexContent>
</xsd:complexType>

This is how the element is called in the schema

<xsd:element name="alien_probe" type="alien_probeType" />

This is how the element appears in the XML document

<alien_probe size="14cm" />

Home
schema schema 2 schema 3 schema 4 schema 5 schema 6 schema 7 schema 8 schema 9
Next

schema 10 schema 11 schema 12 schema 13 schema 14 schema 15 schema 16 schema 17

Page by Howard Rosenbaum
Find me at hrosenba@indiana.edu You are here: http://www.slis.indiana.edu/hrosenba/www/Workshops/XML/Demo/schema15.html