users@jaxb.java.net

Re: Interesting tidbit, has anyone seen this?

From: Sriram Thyagarajan <Sriram_Thyagarajan_at_KEANE-NNE.com>
Date: Thu, 01 May 2003 14:27:53 -0400

>>From my usage, I belive it happens when minOccurs="0", which makes it
optional...

I used it as a feature, which lets the optional xml elements appear in any
order, because the value is set anyway... Even with Unmarshalling with
validation, we can catch the event and ignore it.

Is this a bug ?

-----Original Message-----
From: Han Ming Ong [mailto:hanming_at_mac.com]
Sent: Thursday, May 01, 2003 2:04 PM
To: JAXB-INTEREST_at_JAVA.SUN.COM
Subject: Interesting tidbit, has anyone seen this?


Given this schema fragment

   <xs:element name="local-tx-datasource">
     <xs:complexType>
       <xs:sequence>
         <xs:element minOccurs="0" maxOccurs="unbounded"
ref="user-name"/>
         <xs:element minOccurs="0" maxOccurs="unbounded"
ref="password"/>
         <xs:element minOccurs="0" ref="idle-timeout-minutes"/>
       </xs:sequence>
     </xs:complexType>
   </xs:element>

I realized that JAXB can unmarshal the following XML fragment, where
<password> and <user-name> are out of order and then magically correct
the order during marshalling:

   <local-tx-datasource>
     <password></password>
     <user-name>sa</user-name>
   </local-tx-datasource>

Well, I know, I know, it is probably a bug but what a great side effect
if you don't need validation during unmarshalling :-)

By the way, the magic (or bug) happens when you add
'maxOccurs="unbounded"' to the elements.

Han Ming