XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Daniel PontzerSubject: Restricted Mixed Content
Author: Daniel Pontzer
Date: 28 Feb 2008 05:15 PM
Is there anyway in schema to define an element such that each of the following is legal:

a scalar:
<data>1</data>

or a vector:
<data>1 2 3 4</data>

or a vector of vectors:
<data><cell>1 2 3</cell>
<cell>34</cell>
<cell>15 23 23 15 67</cell>
</data>

in other words, I want mixed content but it should either be text or elements ... can't have both simultaneously.

Thanks
Dan Pontzer

Postnext
Alberto MassariSubject: Restricted Mixed Content
Author: Alberto Massari
Date: 29 Feb 2008 02:14 AM
Hi Daniel,
unless the two versions of <data> occur inside different elements, you cannot have two definitions for the same element name. You could allow both contents as optional, but in this case you would not be able to avoid to have both forms at the same time (or none)

Hope this helps,
Alberto

Postnext
Daniel PontzerSubject: Restricted Mixed Content
Author: Daniel Pontzer
Date: 29 Feb 2008 08:23 AM
Thanks, Alberto, for your prompt response ... if not obvious, my interest was in backward compatibility. In my business, as our target hardware gets more complicated, parameters that were once simple tend to take on more 'dimensionality'. I'd like to be able to support old and new versions of those parameters so old versions of the XML file don't have to be updated to work in the new environment. Can you provide guidance or point me to any white paper that might cover this topic? I'd hate to modify to schema to handle a new element that is in parallel to the original 'data' because that would be distasteful from the perspective of naming the new element since it is essentially the same parameter as the original except that it has gained a dimension. I would analogize this problem to that solved by an overloaded function call that can take on any of N different types of argument lists. Is there no equivalent capability in XML Schema?

Thanks,
Dan Pontzer
(attempting to drag my colleges into the 21st century ... we're way behind the times as far as use of XML goes. The moment I learned about XML (just last year) I saw its practicality and wondered why our software department hasn't been promoting its use. Mostly we do embedded software so were not so 'up to speed' on web stuff which is where XML came from, of course, but its practicality is so far ranging outside of the web)

Posttop
Alberto MassariSubject: Restricted Mixed Content
Author: Alberto Massari
Date: 29 Feb 2008 09:13 AM
Hi Daniel,
you can design a schema that allows the first two options, like in

<xs:simpleType name="vector">
<xs:list itemType="xs:int"/>
</xs:simpleType>
<xs:element name="data" type="vector"/>

or one that validates the last one

<xs:simpleType name="vector">
<xs:list itemType="xs:int"/>
</xs:simpleType>
<xs:element name="cell" type="vector"/>
<xs:element name="data">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="cell"/>
</xs:sequence>
</xs:complexType>
</xs:element>

But in order to have a definition to match both cases, you could add a mixed="true" to the xs:complexType definition, but this would allow any text between the <cell> elements (without checking if they are one or more numbers).
Another attempts could be extending the "vector" type with child nodes:

<xs:element name="data">
<xs:complexType>
<xs:complexContent>
<xs:extension base="vector">
<xs:sequence>

but this is not valid XMLSchema (see thread on http://lists.w3.org/Archives/Public/xmlschema-dev/2001Jan/thread.html#msg67 for the reasons why this has been prohibited).
Or you could try making a choice between the two forms:

<xs:element name="root">
<xs:complexType>
<xs:choice>
<xs:element name="data" type="vector"/>
<xs:element name="data" type="vectorOfVectors"/>
</xs:choice>
</xs:complexType>
</xs:element>

but this grammar would be invalid as there cannot be two elements with the same name but different types in the same scope.

The only valid alternative would be to require each <data> element in the XML to have an xsi:type attribute to signal which type should be used to validate it:

<xs:element name="root">
<xs:complexType>
<xs:choice>
<xs:element name="data" maxOccurs="unbounded"/>
</xs:choice>
</xs:complexType>
</xs:element>

<xs:simpleType name="vector">
<xs:list itemType="xs:int"/>
</xs:simpleType>
<xs:complexType name="vector3d">
<xs:sequence>
<xs:element name="cell" type="vector" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

but the corresponding XML would be

<data xsi:type="vector">1</data>
<data xsi:type="vector">1 2 3 4</data>
<data xsi:type="vector3d">
<cell>1 2 3</cell>
<cell>34</cell>
<cell>15 23 23 15 67</cell>
</data>

that is not backward compatible.

In the end, I think that the best option you have is to define a new element (data3d?) and add a xs:choice between <data> and <data3d>.

Hope this helps,
Alberto

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.