Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > a set of elements occur in any order with multiple occurrences

Reply
Thread Tools

a set of elements occur in any order with multiple occurrences

 
 
mavis
Guest
Posts: n/a
 
      10-10-2006
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

 
Reply With Quote
 
 
 
 
George Bina
Guest
Posts: n/a
 
      10-11-2006
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 xmlnss="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


mavis wrote:
> 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


 
Reply With Quote
 
 
 
 
mavis
Guest
Posts: n/a
 
      10-11-2006
Thanks a lot!!!

-M


George Bina wrote:
> 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 xmlnss="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
>
>
> mavis wrote:
> > 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OT: regular expression matching multiple occurrences of one group pinkisntwell Python 5 11-10-2009 06:57 AM
how to remove multiple occurrences of a string within a list? bahoo Python 37 04-09-2007 12:09 AM
RegEx with multiple occurrences Mike Python 3 05-04-2006 12:11 PM
Multiple occurrences of an xml element Pete XML 1 11-27-2004 03:50 PM
Show 4 Records that occur more often...and how often they occur. Miguel Dias Moura ASP .Net 4 05-06-2004 03:40 PM



Advertisments