• 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

problems enforcing the order of elements that compose a complexType

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry if there's an obvious answer to this....I've been digging and playing and can't get this to work....

I am having problems enforcing the order of optional fields.

In my schema I've defined a complex type that is composed of other complex types. Not all of the composing types have to be present, but whichever are present must be in a specific order.

For some reason, the schema doesn't enforce the order. I've been reading and playing with different combinations of xs:choice and xs:sequence. Doesn't matter what order the composing types are in my XML file - file is unmarshalled and parsed with no complaints (using JAXB).

How can I enforce the order of the composing types? What am I missing here? Here is a snippet of the schema, I didn't include definitions of the composing types. My XML file contains txType2 followed by txType1 and doesn't complain about the sequence.

<xs:complexType name="TransactionCollection">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:appinfo>
<jxb roperty name="TransactionCollection"/>
</xs:appinfo>
</xs:annotation>
<xs:sequence>
<xs:element name="txType1" type="TxType1" minOccurs="0"/>
<xs:element name="txType2" type="TxType2" minOccurs="0"/>
<xs:element name="txType3" type="TxType3" minOccurs="0"/>
<xs:element name="txType4" type="TxType4" minOccurs="0"/>
<xs:element name="txType5" type="TxType5" minOccurs="0"/>
<xs:element name="txType6" type="TxType6" minOccurs="0"/>
</xs:sequence>
</xs:choice>
</xs:complexType>


Thanks in advance for your time and assistance...
 
Ranch Hand
Posts: 578
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Steve Kritzler:

<xs:complexType name="TransactionCollection">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:appinfo>
<jxb roperty name="TransactionCollection"/>
</xs:appinfo>
</xs:annotation>
<xs:sequence>
<xs:element name="txType1" type="TxType1" minOccurs="0"/>
<xs:element name="txType2" type="TxType2" minOccurs="0"/>
<xs:element name="txType3" type="TxType3" minOccurs="0"/>
<xs:element name="txType4" type="TxType4" minOccurs="0"/>
<xs:element name="txType5" type="TxType5" minOccurs="0"/>
<xs:element name="txType6" type="TxType6" minOccurs="0"/>
</xs:sequence>
</xs:choice>
</xs:complexType>


Thanks in advance for your time and assistance...



Hi Steve, you dont need the choice elemnt!! Teh choice elemnt is only if you want either of the lemnts present under it to be present, but not both!

For Example,



The xs:choice indicator in the priceType declaration specifies that
elements of this particular type (Price element) can contain either a dollars
element or a pounds element, but not both.

Comming back to your problem, removing the choice elemnt will solve your problem



if your document now has, txType2 followed by txType1 IT WILL complain about the sequence.


HTH
 
Steve Kritzler
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much for your reply Hari - much appreciated.

I understand your response. Allow me to explain my reasoning for coding the xs:choice....perhaps I am doing something else wrong here....

I need to represent the group of transactions in my XML file as a collection - eventually I will unmarshall the file and then iterate-and-process the transactions within the collection. During processing, I'm doing an instanceof check to determine if the current tx is of type TxType1 or TxType2 etc.

I can't specify minOccurs/maxOccurs on the <xs:complexType name="TransactionCollection"> line. At the time I thought I needed the xs:choice line so that was a logical spot for the min/maxOccurs elements.

If I have to remove xs:choice, how do I represent the mix of possible transactions as a collection?

Again, sorry for a silly question. This seems so straightforward but I can't get this to work. Thanks again for your time and assistance.
 
Hari Vignesh Padmanaban
Ranch Hand
Posts: 578
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm. I am not sure if I undertand your requirement

But, seems liek you want to specify a choice on the "TransactionColelction" also..

So will this work for your rquirement ?




let me know

HTH
 
Steve Kritzler
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again Hari.....

Awesome....not quite, but it's gotten me a LOT closer to where I want to be and I'm very ok with that.

I understand what you're doing with that last code snippet, and I believe I can work with that to get past my little headache.

So, thanks again very much for your help....take care.
reply
    Bookmark Topic Watch Topic
  • New Topic