2

I'm working on an assignment of putting together XML documentation for an event calendar, which consists of event elements that have child elements of name, date, venue, etc. Several events have the same venue but the contact info for each venue is listed only once in the XML data. So, what I have in the XML document:

<venueinfo>
    <venue id="p1">
        <name>...</name>
        <address>...</address>
        ...
    </venue>
    <venue id="p2">
        ...
    </venue>
    ...
</venueinfo>

And in the event elements:

<event>
    <name>...</name>
    ...
    <location idref="p1"/>
    ...
</event>

In XSD I need to link the elements of elements to the corresponding elements in , but so far I haven't got the linking correctly. Here are the pertinent attribute and element declarations:

<-- root element -->
<xs:element name="eventcalendar">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="tapahtuma" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="idref" type="xs:IDREF"/>

<xs:element name="venueinfo">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="venue" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:element name="venue">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="name"/>
            <xs:element ref="address"/>
            ...
        </xs:sequence>
        <xs:attribute ref="id" use="required"/>
    </xs:complexType>
</xs:element>

<xs:element name="location">
    <xs:complexType>
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute ref="idref" use="required"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
</xs:element>

<xs:element name="event">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="category"/>
            ...
            <xs:element ref="location"/>
            ...
        </xs:sequence>
    </xs:complexType>
</xs:element>

Validation of the XML gives me "element 'venueinfo' is not allowed for content model '(event+)'". Could someone advice me as to what I should do to get this correctly? Many thanks.

Maria Niku
  • 51
  • 1
  • 4

1 Answers1

1

Use a type attribute for the event definition, move it to the top of the file, then reference it as a container for the venueinfo structure:

<xs:element name="event" type="tEvent">
...
</xs:element>

<xs:complexType name="tEvent">
 <xs:element name="venueinfo">
 ...
 </xs:element>
</xs:complexType>
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265