a set of elements occur in any order with multiple occurrences

M

mavis

Could you please help me with this xsd definition?

I need to define a set of elements occur in any order with multiple
occurrences, but the same kind of elements need to group together...

Sth like this....

<xs:element name="A">
<xs:complexType>
<xs:all>

<xs:element name="B-1" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>

<xs:element name="B-2" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>

<xs:element name="B-3" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>

<xs:element name="B-4" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>

</xs:all>

</xs:complexType>
</xs:element>

The above definition cannot be validated correctly...

Thanks in advance!

Mavis
 
G

George Bina

Hi,

xs:all has a number of limitations in XML Schema. The closest you can
get with XML schema alone is to specify a 0 to 4 choice of the same
content that you have in xs:all. The full checking can be done either
at application level or using a Schematron rule embedded in the XML
Schema, sull working sample below:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="A">
<xs:complexType>
<xs:annotation>
<xs:appinfo>
<pattern xmlns="http://www.ascc.net/xml/schematron"
name="testGrouping">
<rule context="A">
<assert
test="not(B-1[following-sibling::*[not(self::B-1)][following-sibling::B-1]])">
B-1 elements should stay together. </assert>
<assert
test="not(B-2[following-sibling::*[not(self::B-2)][following-sibling::B-2]])">
B-2 elements should stay together. </assert>
<assert
test="not(B-3[following-sibling::*[not(self::B-3)][following-sibling::B-3]])">
B-3 elements should stay together. </assert>
<assert
test="not(B-4[following-sibling::*[not(self::B-4)][following-sibling::B-4]])">
B-4 elements should stay together. </assert>
</rule>
</pattern>
</xs:appinfo>
</xs:annotation>
<xs:choice maxOccurs="4">
<xs:element name="B-1" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="B-2" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="B-3" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="B-4" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

Basically each assert test not to have an element followed by an
element different than it and then that followed by an element with the
same name as the initial one.

Best Regards,
George
 
M

mavis

Thanks a lot!!!

-M


George said:
Hi,

xs:all has a number of limitations in XML Schema. The closest you can
get with XML schema alone is to specify a 0 to 4 choice of the same
content that you have in xs:all. The full checking can be done either
at application level or using a Schematron rule embedded in the XML
Schema, sull working sample below:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="A">
<xs:complexType>
<xs:annotation>
<xs:appinfo>
<pattern xmlns="http://www.ascc.net/xml/schematron"
name="testGrouping">
<rule context="A">
<assert
test="not(B-1[following-sibling::*[not(self::B-1)][following-sibling::B-1]])">
B-1 elements should stay together. </assert>
<assert
test="not(B-2[following-sibling::*[not(self::B-2)][following-sibling::B-2]])">
B-2 elements should stay together. </assert>
<assert
test="not(B-3[following-sibling::*[not(self::B-3)][following-sibling::B-3]])">
B-3 elements should stay together. </assert>
<assert
test="not(B-4[following-sibling::*[not(self::B-4)][following-sibling::B-4]])">
B-4 elements should stay together. </assert>
</rule>
</pattern>
</xs:appinfo>
</xs:annotation>
<xs:choice maxOccurs="4">
<xs:element name="B-1" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="B-2" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="B-3" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="B-4" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

Basically each assert test not to have an element followed by an
element different than it and then that followed by an element with the
same name as the initial one.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Could you please help me with this xsd definition?

I need to define a set of elements occur in any order with multiple
occurrences, but the same kind of elements need to group together...

Sth like this....

<xs:element name="A">
<xs:complexType>
<xs:all>

<xs:element name="B-1" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>

<xs:element name="B-2" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>

<xs:element name="B-3" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>

<xs:element name="B-4" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>

</xs:all>

</xs:complexType>
</xs:element>

The above definition cannot be validated correctly...

Thanks in advance!

Mavis
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top