Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XML Schema: inheritance with variable order of childs

From: Joe Kesselman <keshlam-nospam@-------.--->
To: NULL
Date: 11/2/2007 7:19:00 PM

Sven wrote:
> But with this schema, the order of "Name" and "Content" is relevant.
> Is there a way to define this in a way that this order is variable?


Just a thought, which I haven't tested: How about starting with an empty 
ItemType, then driving the specific versions from that, each with their 
own independent definition of the content? Something like:

  <xs:complexType name="ItemType">
  </xs:complexType>

<xs:complexType name="TextItemType">
   <xs:complexContent>
     <xs:extension base="ItemType">
       <xs:sequence maxOccurs="unbounded" minOccurs="1">
         <xs:choice>
           <xs:element name="Name" type="xs:string" />
           <xs:element name="Content" type="xs:string" />
         </xs:choice>
       </xs:sequence>
     </xs:extension>
   </xs:complexContent>
</xs:complexType>

<xs:complexType name="OtherItemType">
   <xs:complexContent>
     <xs:extension base="ItemType">
       <xs:sequence maxOccurs="unbounded" minOccurs="1">
         <xs:choice>
           <xs:element name="Name" type="xs:string" />
           <xs:element name="Number" type="xs:integer" />
         </xs:choice>
       </xs:sequence>
     </xs:extension>
   </xs:complexContent>
</xs:complexType>

Of course this does have the problem that each kind of ItemType can have 
multiple instances of its fields; if that's an issue, see past posts 
here and in the XSLT FAQ for (somewhat painful) ways to overcome that. 
And I think you'd have to use xsi:type to tell the validator which type 
you intended this particular element to conform to.

BTW, the _good_ fixes are either to make folks provide the values in a 
stereotyped order, unless the variability is actually necessary for your 
application (any decent coder, and any human, ought to be able to follow 
that simple set of instructions)... or to recognize that XML Schema 
really isn't intended to capture every possible constraint, and to 
impose some of them in documentation and in application-level tests.



-- 
() ASCII Ribbon Campaign  | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent