Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XML Schema: inheritance with variable order of childs

From: Pavel Lepin <p.lepin@-------.--->
To: NULL
Date: 11/2/2007 3:28:00 PM


Sven <sven@a...> wrote in
<1194007305.931018.87630@5...>:
> <TextItem>
>   <Name>Temperature</Name>
>   <Content>27°C</Content>
> </TextItem>
> <TextItem>
>   <Content>cloudy</Content>
>   <Name>Sky</Name>
> </TextItem>
> 
> With a variable sequence order for Name and Content I can
> define this as:
> 
> <xs:complexType name="TextItemType">
>   <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:complexType>

Which is too lax.

> As I want define different Item types I define a base type
> Item and derive the special content types:
> 
> <xs:complexType name="ItemType">
>   <xs:sequence>
>       <xs:element  maxOccurs="1" minOccurs="1" name="Name"
> type="xs:string" />
>   </xs:sequence>
> </xs:complexType>
> 
> <xs:complexType name="TextItemType">
>   <xs:complexContent>
>     <xs:extension base="ItemType">
>       <xs:sequence>
>         <xs:element  maxOccurs="1" minOccurs="1"
>         name="Content"
> type="xs:string" />
>       </xs:sequence>
>     </xs:extension>
>   </xs:complexContent>
> </xs:complexType>
> 
> 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?

I believe the answer is no, but you'd have to hire a
language lawyer to quote chapter and verse on it. Anyway,
that's beside the point, because you cannot differentiate
element types based on element content. xsi:type is the
only way around it and it's, well, clunky. See newsgroup
archives, this is one of the most commonly asked questions
about XML Schemata.

The standard recommendations are:

  1. Stop wanting that.
  2. Use a more powerful schema definition language.
  3. Validate on application side, not on parser side.
  4. Design a well-structured document:

      <temperature scale="celsius">27</temperature>
      <sky>cloudy</sky>

Another interesting way of dealing with modestly crippled
XML documents is transforming them into something sane
using XSLT. Make the transformation scream and swear if it
runs into something that shouldn't be there, and you're
golden.

-- 
"I can't help but wonder if you... don't know a hell of a
lot more about practically every subject than Solomon ever
did."


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