Variable order of elements in xsd

This should cover W3C XML Schema, Relax NG and DTD related problems.
ody13
Posts: 2

Variable order of elements in xsd

Thu Nov 11, 2004 7:24 pm

Hallo,

this is my code:

<xs:element name="layer">
<xs:complexType>
<xs:choice>
<xs:element name="paragraph" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="position" type="xs:string"/>
<xs:attribute name="alignment" type="xs:string"/>
<xs:attribute name="character_size" type="xs:decimal"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="image" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="position" type="xs:string"/>
<xs:attribute name="scale" type="xs:decimal"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="model" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="position" type="xs:string"/>
<xs:attribute name="rotate" type="xs:string"/>
<xs:attribute name="scale" type="xs:decimal"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>

The problem is that I don't know and I don't wanna specify when the elements "image", "paragraph and "model" accure. I'm looking for a way to have a variable order. The Problem is, that the number of times the element accure is variable, too. It could be like this for example:

image
paragraph
image
image

Without "model" at all.

Thanx for the solution in advance.

-ODY
george
Site Admin
Posts: 2100

Thu Nov 11, 2004 9:37 pm

Hi,

You have specified a model like
( (paragraph)* | (image)* | (model)* )
that is either zero or more pharagraph or zero or more image or zero or more mode.

From your message it seems that you want
(paragraph | image | model)*

That is XML Schema notation will look like

Code: Select all

<xs:element name="layer">
    <xs:complexType>
        <xs:choice maxOccurs="unbounded" minOccurs="0">
            <xs:element name="paragraph">
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="xs:string">
                            <xs:attribute name="position" type="xs:string"/>
                            <xs:attribute name="alignment" type="xs:string"/>
                            <xs:attribute name="character_size" type="xs:decimal"/>
                        </xs:extension>
                    </xs:simpleContent>
                </xs:complexType>
            </xs:element>
            <xs:element name="image">
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="xs:string">
                            <xs:attribute name="position" type="xs:string"/>
                            <xs:attribute name="scale" type="xs:decimal"/>
                        </xs:extension>
                    </xs:simpleContent>
                </xs:complexType>
            </xs:element>
            <xs:element name="model">
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="xs:string">
                            <xs:attribute name="position" type="xs:string"/>
                            <xs:attribute name="rotate" type="xs:string"/>
                            <xs:attribute name="scale" type="xs:decimal"/>
                        </xs:extension>
                    </xs:simpleContent>
                </xs:complexType>
            </xs:element>
        </xs:choice>
    </xs:complexType>
</xs:element>


Best Regards,
George
ody13
Posts: 2

Fri Nov 12, 2004 1:11 pm

thanx, works great...

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 1 guest