Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: A schema that uses attribute values to enforce content structure rules?

From: Boris Kolpackov <boris@-------------.--->
To: Nathan Potter <ndp@----.-----------.--->
Date: 1/19/2009 10:24:00 AM
Hi Nathan,

Nathan Potter <ndp@c...> writes:

> I am trying to express the semantics of our content model in an XML  
> schema. I have a type whose allowed content is function of the values  
> of an attribute. Here's a simplified "sketch" of the problem:
> 
> An element <A> has a required attribute "type", if A@type=="xml" then  
> <A> may contain any (other namespace) XML:
> 
>     <A type="xml">
>         <foo:B />
>         <bar:C />
>     </A>
> 
> If A@type=="Container" then <A> may any number of other <A> elements:
> 
>     <A type="Container">
> 	<A type="xml">
>             <foo:B />
>         </A>
> 	<A type="Container">
> 	    <A type="xml">
>                 <bar:C />
>             </A>
>         </A>
>     </A>
> 
> If A@type=="values" then <A> must contain one or more <value> elements:
> 
>     <A type="values">
>         <value>1234</value>
>     </A>

You can do this but you will need to use the special xsi:type attribute
instead of just type. You will need to define an abstract base type for 
element A:

<complexType name="base" abstract="true"/>

Then you would define three types, xml, container, and values, that 
derive from this type and define the corresponding content models.

You may also want to consider embedding the type information directly
into the element name, for example:

<Container>
  <xml>
    <foo:B />
  </xml>
  <Container>
    <xml>
      <bar:C />
    </xml>
  </Container>
</Container>

This gives you a much cleaner vocabulary. You can do this in an
extensible manner using substitution groups.

Boris

-- 
Boris Kolpackov, Code Synthesis Tools   http://codesynthesis.com/~boris/blog
Open source XML data binding for C++:   http://codesynthesis.com/products/xsd
Mobile/embedded validating XML parsing: http://codesynthesis.com/products/xsde

From tobias.koenig@t... Wed Jan 21 16:43:11 2009
Received: from bart.w3.org ([128.30.52.63])
	by frink.w


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