• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

question - "all" group

 
Ranch Hand
Posts: 1011
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I have a question about <all>.
I used the IBM WebShpere Application Developer (WSAD) studio to the following:
I created an XML schema (po-use-all.xsd):
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="purchaseOrder" type="PurchaseOrderType"/>

<xsd:element name="comment" type="xsd:string"/>

<xsd:complexType name="PurchaseOrderType">
<xsd:sequence>
<xsd:element name="shipTo" type="xsd:string"/>
<xsd:element name="billTo" type="xsd:string"/>
<xsd:element ref="comment" minOccurs="0"/>
<xsd:element name="items" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="orderDate" type="xsd ate"/>
</xsd:complexType>
</xsd:schema>
And then I created an instance document (po-use-all.xml):
<?xml version="1.0" encoding="UTF-8"?>
<purchaseOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xml_schema/po-use-all.xsd">
<shipTo>shpping address</shipTo>
<billTo>billing address</billTo>
<comment>This is comment</comment>
<items>items string</items>
</purchaseOrder>
When I switch the places of <shipTo> and <billTo>, the WSAD gives an error.
Anyone has any ideas? Thanks,
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The xsd:sequence group requires that each element in the group appear exactly once, in the specified order.
From - http://www.ibiblio.org/xml/books/bible2/chapters/ch24.html#d1e2436
Cheers,
Dan
 
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tong,
Dan already gave you the reason as to why you are facing the problem. A little addition to that -
<xsd:sequence>
<xsd:element name="ele1" type="xsd:string"
minOccurs="2" maxOccurs="unbounded"/>
<xsd:element name="ele2" type="xsd:string"/>
</xsd:sequence>
If this is the case, you need to have 2 ele1s followed by an ele2 (default value for minOccurs and maxOccurs is 1). Hence you can have multiple occurances of the same element, but all of them should follow the sequence of the bigger group defined by <xsd:sequence>.
 
Tong Chen
Ranch Hand
Posts: 1011
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dan & Jayadev, Thank you both!
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jayadev
Your explanation of sequence is wrong, go to the link dan provided, please!

The xsd:all group requires that each element in the group must occur at most once, but that order is not important.
The xsd:choice group specifies that any one element from the group should appear. It can also be used to say that between N and M elements from the group should appear in any order.
The xsd:sequence group requires that each element in the group appear exactly once, in the specified order.


I had doubt when I first read it, but did not have time to find out. Now, I'm clear!
Tony, you "Thank you both!", however, they are saying different and conflict things.
[ November 09, 2002: Message edited by: Roseanne Zhang ]
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Roseanne,
I'm using the xsv schema validator given by Roger Costello at xfront website. I tried it on one of the examples, excerpts shown here -
================================================
<xsd:element name="globalElement1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="localElement3" type="xsd:string" minOccurs="2"
maxOccurs="unbounded"/>
<xsd:element name="localElement4" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="jaya" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
================================================
<globalElement1 jaya="jaya1">
<localElement3/>
<localElement3/>
<localElement4/>
</globalElement1>
=================================================
This got validated successfully. Seems like the schema validator is not validating as per the rules laid out by W3C !!!
I think its always good to practice things differently by trying to go against the rules and learn in the process. What i just wanted to say was that the posting i made previously was based on the above example i tried.
BTW, Tony's appreciation was merely based on the fact that we guys attempted to resolve the problem he was having, not whether one was correct or not Its always a nice gesture to appreciate any help. I hope he is going to post a thank you note to you also
Have a nice time.
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Roseanne,
My interpretation of the stuff is wrong. It would have been awfully nice had you given details as to why it was wrong. I'm trying to put my explanation below -
Dan quote was correct -

The xsd:sequence group requires that each element in the group appear exactly once, in the specified order.


The example i gave thinking it to be violating the above statement is given here -

<xsd:sequence>
<xsd:element name="ele1" type="xsd:string"
minOccurs="2" maxOccurs="unbounded"/>
<xsd:element name="ele2" type="xsd:string"/>
</xsd:sequence>


The irony is that my example is still in compliance with Dan's statement, but the way in which i thought it out was wrong.
If we have one more look at Dan's quote,

The xsd:sequence group requires that each element in the group appear exactly once(IN THE SCHEMA), in the specified order.


Hence an attempt like the below(repeating the ele1 declaration) is violating the above statement -

<xsd:sequence>
<xsd:element name="ele1" type="xsd:string"
minOccurs="2" maxOccurs="unbounded"/>
<xsd:element name="ele2" type="xsd:string"/>
</xsd:sequence>
<xsd:element name="ele1" type="xsd:string"
minOccurs="2" maxOccurs="unbounded"/>


I hope i'm upto the point this time. Please correct me if i'm not.
Thanks.
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, jayadev
I think you are correct. I was confused by the terminologies they used.
Now, it is clearer after your explanation. I need to find time to practice a little more.
Roseanne
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also a little addition to this -

<xsd:sequence>
<xsd:element name="ele1" type="xsd:string"
minOccurs="2" maxOccurs="unbounded"/>
<xsd:element name="ele2" type="xsd:string"/>
</xsd:sequence>
<xsd:element name="ele1" type="xsd:string"
minOccurs="2" maxOccurs="unbounded"/>


I only get a schema warning for the above attempt with xsv.
Also Roger's tutorial xml-schemas2.ppt on page.4 has the following as a valid thing when explaining about namespaces stuff.

<xsd:element name="foo">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="bar" type="xsd:string"/>
...
<xsd:element name="bar" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType
</xsd:element>

 
reply
    Bookmark Topic Watch Topic
  • New Topic