[XMLSCHEMA-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

From: Nathan Potter <ndp@coas.oregonstate.edu>
Date: Tue, 27 Jan 2009 16:44:36 -0800
Cc: Nathan Potter <ndp@coas.oregonstate.edu>, xmlschema-dev@w3.org
Message-Id: <4672E44D-009A-4A14-A84F-77E05AF29DF6@coas.oregonstate.edu>
To: Boris Kolpackov <boris@codesynthesis.com>
Re: A schema that uses attribute values to enforce content structure rules?


I tried several variations on this but ended up painted into a corner  
every time. In the end I refactored the representation entirely so  
that each type has it's own type:

<document xmlns:a="http://my.namespace/url">
     <a:Xml>
         <foo:B />
         <bar:C />
     </a:Xml>
     <a:Container>
         <a:Xml>
             <foo:B />
             <bar:C />
         </a:Xml>
         <a:Container>
             <a:Xml>
                 <bar:C />
             </a:Xml>
         </a:Container>

         <Values>
             <a:value>foo</a:value>
             <a:value>foofy</a:value>
             <a:value>food</a:value>
         </a:Values>

     </a:Container>
</document>

And was able to explicitly define the content of each type. Michael  
Kay's point about XSD 1.0 and "conditional type assignment" really  
helped me reevaluate the problem space.

Thanks for all your help,

Nathan



On Jan 18, 2009, at 10:24 PM, Boris Kolpackov wrote:

>
> Hi Nathan,
>
> Nathan Potter <ndp@coas.oregonstate.edu> 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
>

============================================================
Nathan Potter                 Oregon State University, COAS
ndp at coas.oregonstate.edu   104 Ocean. Admin. Bldg.
541 737 2293 voice            Corvallis, OR   97331-5503
541 737 2064 fax
Received on Wednesday, 28 January 2009 00:45:19 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.