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

L595 XML@IU logo

Creating Schemas

Grouping elements in complex types

Using the group facet a range of elements can be grouped together and reused as a group in a schema

A group is equivalent to a parameter entity in a DTD

The generic form is:

<xsd:group name="name">
    <xsd:sequence>
        <xsd:element name="name1" type="type" />
        <xsd:element name="name2" type="type" />
        <xsd:element name="name3" type="type" />
    </xsd:sequence>
</xsd:group>

An example is:

<xsd:group name="alien_tools">
    <xsd:sequence>
        <xsd:element name="tubes" type="xsd:string" />
        <xsd:element name="shape" type="xsd:string" />
        <xsd:element name="duration" type="xsd:integer" />
    </xsd:sequence>
</xsd:group>

To use the group in a schema, it must be referenced

This is necessary because it has been globally defined

This is done with the group ref attribute

The generic form is

<xsd:group ref="groupName" />

An example is

<xsd:group ref="alien_tools" />

Here's how it is used

<xsd:element name="alien_probes">
    <xsd:complexType>
        <xsd:sequence>
            <element name="name" type="xsd:string" />
            <element name="date" type="xsd:timeInstant" />
            <xsd:group ref="alien_tools" />
            <element name="effects" type="xsd:string" />
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

It would be used in the XML file like this

<alien_probes>
    <name>
I.B. Gone</name>
    <date>
2001-05-22T12:10:45UTC-5</date>
    <tubes type="metallic">
12"</tubes>
    <shape>
Curved</shape>
    <duration>
P4H13M</duration>
    <effects>
Memory loss</effects>
<alien_probes>

And in a different element

<xsd:element name="alien_abduction">
    <xsd:complexType>
        <xsd:sequence>
            <element name="location" />
            <element name="craft_type" type="hypersonic" />
            <element name="time_lost" type="4 hours" /
            <xsd:group ref="alien_tools" />
        </xsd:sequence>
    </xsd:complexType>
</xsd:element >

It would be used in the XML file like this

<alien_probes>
    <location>
Bloomington IN</location>
    <craft_type>
Saucer</craft_type>
    <time_lost>
P3H14M</time_lost>
    <tubes type="metallic">
6"</tubes>
    <shape>
Straight</shape>
    <duration>
P14H35M22S</duration>
<alien_probes>

Like simple types, complex types can be named or anonymous

Also like simple types they can also be globally or locally declared

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/schema12.html