Newbie question, schema, complex types and unordered multiple elemets

D

davidjones

I want to model a situation where you can have multiple children of an
element, and the children can be different types and in any order. A
simple example of what I mean is at [1]. I am trying to make a schema
to define this document, my attempted schema at [2].

If I understand the format correctly I need to make the parent element
(building) a complex type, and this must have an order indicator to
contain other elements. None of the 3 order indicators (All, Choice,
Sequence) fit my model.

How do I do this? It seems I am missing something fundamental, or I
am trying to model data that cannot be fit to xml.

Thank you for any help.

[1]
<building name="house1">
<window state="open"/>
<door state="open"/>
<door state="closed"/>
<window state="closed"/>
</building>

[2]
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="building">
<xs:annotation>
<xs:documentation>a building</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence> <!-- This tag is the problem -->
<xs:element name="window" maxOccurs="unbounded">
</xs:complexType>
</xs:element>
<xs:element name="door" maxOccurs="unbounded">
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
 
U

usenet

I want to model a situation where you can have multiple children of an
element, and the children can be different types and in any order. A
simple example of what I mean is at [1]. I am trying to make a schema
to define this document, my attempted schema at [2].

If I understand the format correctly I need to make the parent element
(building) a complex type, and this must have an order indicator to
contain other elements. None of the 3 order indicators (All, Choice,
Sequence) fit my model.

How do I do this? It seems I am missing something fundamental, or I
am trying to model data that cannot be fit to xml.

Thank you for any help.

[1]
<building name="house1">
<window state="open"/>
<door state="open"/>
<door state="closed"/>
<window state="closed"/>
</building>

[2]
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="building">
<xs:annotation>
<xs:documentation>a building</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence> <!-- This tag is the problem -->
<xs:element name="window" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="state" type="xs:string" use="required"/

</xs:complexType>
</xs:element>
<xs:element name="door" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="state" type="xs:string" use="required"/

</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

One thing that might work for you is changing the xs:sequence in your
schema to:

<xs:choice maxOccurs="unbounded">...

HTH,

Pete.
=============================================
Pete Cordell
Codalogic
for XML Schema to C++ data binding visit
http://www.codalogic.com/lmx/
=============================================
 
D

davidjones

One thing that might work for you is changing the xs:sequence in your
schema to:

<xs:choice maxOccurs="unbounded">...

Thanks, that does exactly what I want. It does not seems to do what
w3schools says it does:

from http://www.w3schools.com/schema/schema_complex_indicators.asp

The <choice> indicator specifies that either one child element or
another can occur:

Is there a more accurate description of what these tags really mean?

Thank you for the help.
 
J

Joseph Kesselman

Thanks, that does exactly what I want. It does not seems to do what
w3schools says it does:

Unfortunately, most of what I've heard about w3schools suggests that it
isn't a particuarly well-organized resource (often not complete,
sometimes not accurate).

Choice says that any of the contained items can occur at this point. The
default if those aren't specified is exactly one instance of the choice,
no more and no less, but the standard Schema attributes such as
maxOccurs can be used to change that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top