IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

XSD Indicators or Compositors Options · View
xsd_newbie
Posted: Monday, July 13, 2009 10:33:36 PM
Rank: Newbie

Joined: 7/13/2009
Posts: 2
Location: Pasadena, CA
Hi everyone,

I'd like to know how I can modify an existing XSD so it can be more flexible. I have perhaps hundreds of complex elements which are defined with the <sequence> indicator, but the order in which the child elements are given really does not matter. I would like to permit any of the child elements written, but not require them in order (as with sequence indicator), nor require that they are ALL given (as with all indicator). Is there a way I can do this using XSD 2.20?

Bonus question:

I also have at least one complex type defined with <sequence> that contains a "nested" <choice>. If a change can be made to achieve my first goal, will this nested <choice> be affected?

EXAMPLE:

<xsd:complexType name="Sample">
<xsd:sequence>
<xsd:element minOccurs="0" ref="name" />
<xsd:choice>
<xsd:element ref="Person" />
<xsd:element ref="Organization" />
</xsd:choice>
<xsd:element minOccurs="0" maxOccurs="unbounded" ref="Address" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID" use="required" />
</xsd:complexType>
island
Posted: Tuesday, July 14, 2009 10:24:48 AM
Rank: Newbie

Joined: 10/28/2002
Posts: 1,283
Location: AT
Hi newbie,

try using a choice compositor instead of a sequence or all, and then setting the minOccurs to "0" and the maxOccurs to "unbounded" on this compositor. The elements within the choice can then appear or not appear in any order.



xsd_newbie
Posted: Tuesday, July 14, 2009 6:54:33 PM
Rank: Newbie

Joined: 7/13/2009
Posts: 2
Location: Pasadena, CA
island wrote:
Hi newbie,

try using a choice compositor instead of a sequence or all, and then setting the minOccurs to "0" and the maxOccurs to "unbounded" on this compositor. The elements within the choice can then appear or not appear in any order.





Thank you island,

I did try your suggestion, but it looks like <choice> is forcing an either/or situation. Once the first element is accepted, all others generate an error since the "choice" has been made. My understanding is that <choice> does not allow more than one of the child elements to be defined in the XML. Is that true?

Any other suggestions?
vlad
Posted: Wednesday, July 15, 2009 8:01:43 AM
Rank: Advanced Member

Joined: 12/13/2005
Posts: 2,856
Location: Mauritius
You should use ALL, but set every element to minOccurs = 0 which would mean they are not required.
island
Posted: Thursday, July 16, 2009 8:53:55 AM
Rank: Newbie

Joined: 10/28/2002
Posts: 1,283
Location: AT
RE [quote] I did try your suggestion, but it looks like <choice> is forcing an either/or situation. Once the first element is accepted, all others generate an error since the "choice" has been made. My understanding is that <choice> does not allow more than one of the child elements to be defined in the XML. Is that true[ quote]


if you have an UNBOUNDED choice then you would allow any of the elements to occur and they could occur in any order e.g.:


Code:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="a">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="b">
                    <xs:complexType>
                        <xs:choice minOccurs="0" maxOccurs="unbounded">
                            <xs:element name="c" type="xs:string"/>
                            <xs:element name="d" type="xs:string"/>
                            <xs:element name="e" type="xs:string"/>
                        </xs:choice>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>


All of the following would be valid instances of this file:

Code:


<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2008 rel. 2 sp2 (https://www.altova.com)-->
<a xsi:noNamespaceSchemaLocation="test.xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <b>
        <d/>
        <e/>
        <c/>
    </b>
</a>



Code:


<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2008 rel. 2 sp2 (https://www.altova.com)-->
<a xsi:noNamespaceSchemaLocation="test.xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <b>
        <e/>
        <d/>
    </b>
</a>



etc.. etc..

this would ALSO allow the elements to appear more than once however i.e.:

<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2008 rel. 2 sp2 (https://www.altova.com)-->
<a xsi:noNamespaceSchemaLocation="test.xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<b>
<e/>
<d/>
<e/>
</b>
</a>


whereas an ALL compositor as Vlad points out would allow the elements to appear appear in any order but each element could only appear a maximum of one time.
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.