Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 23rd, 2006, 10:45 PM
cmay
Guest
 
Posts: n/a
Default trouble getting correct schema

I am beginning to wonder if it is not possible to get this working.

I am trying to do:

<root>
<a/>
<b/>
<c/>
</root>

With the following conditions:
1) a,b,c can be in any order
2) a and b can only be used 1 time
3) c can be used 0 to unbounded times.

Trying to do this with sequence, choice, all, each seem to miss one
part of the requirements.

Is this not possible?

  #2  
Old July 24th, 2006, 03:35 PM
George Bina
Guest
 
Posts: n/a
Default Re: trouble getting correct schema

It is possible:

c*, (a, c*, b)|(b, c*, a), c*


<xs:element name="a"/>
<xs:element name="b"/>
<xs:element name="c"/>

<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="c" minOccurs="0" maxOccurs="unbounded"/>
<xs:choice>
<xs:sequence>
<xs:element ref="a"/>
<xs:element ref="c" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="b"/>
</xs:sequence>
<xs:sequence>
<xs:element ref="b"/>
<xs:element ref="c" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="a"/>
</xs:sequence>
</xs:choice>
<xs:element ref="c" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

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

cmay wrote:
Quote:
I am beginning to wonder if it is not possible to get this working.
>
I am trying to do:
>
<root>
<a/>
<b/>
<c/>
</root>
>
With the following conditions:
1) a,b,c can be in any order
2) a and b can only be used 1 time
3) c can be used 0 to unbounded times.
>
Trying to do this with sequence, choice, all, each seem to miss one
part of the requirements.
>
Is this not possible?
  #3  
Old July 24th, 2006, 08:15 PM
cmay
Guest
 
Posts: n/a
Default Re: trouble getting correct schema

George,

Thanks for the reply and suggestion.

It looks like you are creating optional lists that depict the different
orders that could appear.

So while this might be doable for a,b,c the list would quickly grow out
of control if it were to expand from 3 possible elements to 10 or more.

Is that right?


Chris




George Bina wrote:
Quote:
It is possible:
>
c*, (a, c*, b)|(b, c*, a), c*
>
>
<xs:element name="a"/>
<xs:element name="b"/>
<xs:element name="c"/>
>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="c" minOccurs="0" maxOccurs="unbounded"/>
<xs:choice>
<xs:sequence>
<xs:element ref="a"/>
<xs:element ref="c" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="b"/>
</xs:sequence>
<xs:sequence>
<xs:element ref="b"/>
<xs:element ref="c" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="a"/>
</xs:sequence>
</xs:choice>
<xs:element ref="c" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
>
Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
>
cmay wrote:
Quote:
I am beginning to wonder if it is not possible to get this working.

I am trying to do:

<root>
<a/>
<b/>
<c/>
</root>

With the following conditions:
1) a,b,c can be in any order
2) a and b can only be used 1 time
3) c can be used 0 to unbounded times.

Trying to do this with sequence, choice, all, each seem to miss one
part of the requirements.

Is this not possible?
  #4  
Old July 24th, 2006, 08:45 PM
Joe Kesselman
Guest
 
Posts: n/a
Default Re: trouble getting correct schema

cmay wrote:
Quote:
So while this might be doable for a,b,c the list would quickly grow out
of control if it were to expand from 3 possible elements to 10 or more.
Is that right?
Some constraints are better expressed in the application than in the schema.
  #5  
Old July 25th, 2006, 09:45 AM
George Bina
Guest
 
Posts: n/a
Default Re: trouble getting correct schema

Hi Chris,

Yes, that is correct.
It is easy to create a more relaxed model and add these constraints at
some other level, at application level as Joe suggested or you can use
embedded Schematron rules inside XML Schema. You can find a working XML
Schema with embedded Schematron rules below.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="a"/>
<xs:element name="b"/>
<xs:element name="c"/>

<xs:element name="root">
<xs:annotation>
<xs:appinfo>
<pattern xmlns="http://www.ascc.net/xml/schematron"
name="testRootContent">
<rule context="root">
<assert test="count(a)=1">a should be used 1 time.</assert>
<assert test="count(b)=1">b should be used 1 time.</assert>
</rule>
</pattern>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="a"/>
<xs:element ref="b"/>
<xs:element ref="c"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

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


cmay wrote:
Quote:
George,
>
Thanks for the reply and suggestion.
>
It looks like you are creating optional lists that depict the different
orders that could appear.
>
So while this might be doable for a,b,c the list would quickly grow out
of control if it were to expand from 3 possible elements to 10 or more.
>
Is that right?
>
>
Chris
>
>
>
>
George Bina wrote:
Quote:
It is possible:

c*, (a, c*, b)|(b, c*, a), c*


<xs:element name="a"/>
<xs:element name="b"/>
<xs:element name="c"/>

<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="c" minOccurs="0" maxOccurs="unbounded"/>
<xs:choice>
<xs:sequence>
<xs:element ref="a"/>
<xs:element ref="c" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="b"/>
</xs:sequence>
<xs:sequence>
<xs:element ref="b"/>
<xs:element ref="c" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="a"/>
</xs:sequence>
</xs:choice>
<xs:element ref="c" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

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

cmay wrote:
Quote:
I am beginning to wonder if it is not possible to get this working.
>
I am trying to do:
>
<root>
<a/>
<b/>
<c/>
</root>
>
With the following conditions:
1) a,b,c can be in any order
2) a and b can only be used 1 time
3) c can be used 0 to unbounded times.
>
Trying to do this with sequence, choice, all, each seem to miss one
part of the requirements.
>
Is this not possible?
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles