users@jaxb.java.net

Unordered elements (<all>) and type extension

From: Lee Breisacher <LBreisacher_at_seagullsw.com>
Date: Wed, 10 Nov 2004 03:49:28 -0500

This is more of an XML Schema question than a jaxb-specific question,
but it came up while trying to do something with jaxb and I thought
maybe a jaxb expert could answer it. Say I have XML like this:

<top>
  <A>
     <child1/>
     <child2/>
  </A>
  <B>
     <child2/>
     <child1/>
     <child3/>
  </B>
  <C>
     <child4/>
     <child1/>
     <child2/>
  </C>
</top>

In words: All of A, B, and C have child1 and child2 in any order. B can
have child3 and C can have child4 in addition to child1 and child2.

The question is how to express this in XML Schema? This works:

<xs:element name="A">
   <xs:complexType>
      <xs:all>
         <xs:element name="child1" type="...."/>
         <xs:element name="child2" type="...."/>
      </xs:all>
   </xs:complexType>
</xs:element>
<xs:element name="B">
   <xs:complexType>
      <xs:all>
         <xs:element name="child1" type="...."/>
         <xs:element name="child2" type="...."/>
         <xs:element name="child3" type="...."/>
      </xs:all>
   </xs:complexType>
</xs:element>
<xs:element name="C">
   <xs:complexType>
      <xs:all>
         <xs:element name="child1" type="...."/>
         <xs:element name="child2" type="...."/>
         <xs:element name="child4" type="...."/>
      </xs:all>
   </xs:complexType>
</xs:element>

But, I'd really like to have the child1/child2 pair as separate type.
What I would like to do is make a type consisting of child1 and child2
in any order, like this:

<xs:complexType name="A">
   <xs:all>
      <xs:element name="child1" type="...."/>
      <xs:element name="child2" type="...."/>
   </xs:all>
</xs:complexType>

Then use that type as the base to make B and C be extensions, like this:

<xs:element name="B">
   <xs:complexType>
      <xs:complexContent>
         <xs:extension base="A">
            <xs:all>
               <xs:element name="child3" type="...."/>
            </xs:all>
         </xs:extension>
      </xs:complexContent>
   </xs:complexType>
</xs:element>

But alas, the above does not work because <xs:all> has a pile of
restrictions on its use -- not nearly as "flexible" as <xs:sequence>.
If I replace <xs:all> with <xs:sequence>, it parses and generates code,
but it is not what I want. I need the children to be in any order. Note
that I do not have control over the XML - I'm just trying to create XML
Schema (and jaxb generated classes) for some existing XML.

So, any suggestions?

Thanks,

Lee

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net