[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]
Re: [xml-dev] An element with more than one possible type
- From: noah_mendelsohn@us.ibm.com
- To: Rick Marshall <rjm@zenucom.com>
- Date: Tue, 6 Feb 2007 19:22:13 -0500
I believe it's fair to say that there will likely be a number of ways of
solving this problem in Schema 1.1, should it go forward to Recommendation
status. Since some of the mechanisms I have in mind have not yet been
clearly explained in public working drafts, I'll have to hold off on
discussing them in detail on this public list. I expect that detailed
proposals will be available publicly quite soon. Roughly, you can look
for mechanisms that will apply Schematron-like XPath predicates to the
subtree validated by a complex type. Furthermore, there is some chance
that the final Recommendation will provide means for choosing the type
itself based on the value of attribute(s) other than xsi:type. So, if
you're interested in a W3C XML Schema-based solution, keep an eye on the
Schema 1.1 working drafts as they come out.
Noah
--------------------------------------
Noah Mendelsohn
IBM Corporation
One Rogers Street
Cambridge, MA 02142
1-617-693-4036
--------------------------------------
Rick Marshall <rjm@zenucom.com>
02/04/2007 01:22 AM
To: pau carre <pau.carre@gmail.com>
cc: xml-dev@lists.xml.org, (bcc: Noah
Mendelsohn/Cambridge/IBM)
Subject: Re: [xml-dev] An element with more than one
possible type
curious about this. why not the traditional data solution of an extra
attribute specifying the type of measure? as in
<item name="water" measure="volume" value="22" />
it also opens up lots of extra, easy, possibilities for analysis.
Rick
pau carre wrote:
> I am trying to code a XML Schema (XSD file) for a web service in such
> a way:
>
> <items>
> <item name = "water" volume ="22">
> <item name = "meat" weight = "10" >
> </items>
>
> It is to say, if name is "water" , then use the "volume" attribute.
> When name is "meat" then use "weight" attribute.
>
> What I have done is to define a simple type for name attribute
>
> <xs:simpleType name="nameType">
> <xs:restriction base="xs:string">
> <xs:enumeration value="water"/>
> <xs:enumeration value="meat"/>
> </xs:restriction>
> </xs:simpleType>
>
> Then I defined an abstract complex type for "item" element:
>
> <xs:complexType name="itemType" abstract = "true">
> <xs:attribute name = "name" type = "nameType"/>
> </xs:complexType>
>
> I restricted the "name" attribute to "meat":
>
> <xs:complexType name="itemTypeMeat">
> <xs:complexContent>
> <xs:restriction base="itemType">
> <xs:attribute name = "name" type = "nameType"
> fixed="meat"/>
> </xs:restriction>
> </xs:complexContent>
> </xs:complexType>
>
> ... and finally I added an attribute "weight":
>
> <xs:complexType name="itemTypeMeatWeight">
> <xs:complexContent>
> <xs:extension base="itemTypeMeat">
> <xs:attribute name = "weight" type = "xs:int"/>
> </xs:extension>
> </xs:complexContent>
> </xs:complexType>
>
> For the "water" is the same as "meat". First I restricted the "name"
> attribute to "water":
>
> <xs:complexType name="itemTypeWater">
> <xs:complexContent>
> <xs:restriction base="itemType">
> <xs:attribute name = "name" type = "nameType"
> fixed="water"/>
> </xs:restriction>
> </xs:complexContent>
> </xs:complexType>
>
> ... and finally I added the "volume" attribute
>
> <xs:complexType name="itemTypeWaterVolume">
> <xs:complexContent>
> <xs:extension base="itemTypeWater">
> <xs:attribute name = "volume" type = "xs:int"/>
> </xs:extension>
> </xs:complexContent>
> </xs:complexType>
>
> The problem is to define the type for "item" element. If I use
> "itemType" as type it the XML does not validated because
> "itemType" is abstract. I I use:
>
> <xs:element name="items">
> <xs:complexType>
> <xs:sequence>
> <xs:choice>
> <xs:element name="item"
> type="itemTypeWaterVolume"/>
> <xs:element name="item"
> type="itemTypeMeatWeight"/>
> </xs:choice>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
>
> the XML does not validate because the validator assumes that the
> "item" type is the first defined (itemTypeWaterVolume). If I
> change the declaration of "item" element then the validator
> assumes that the type of "item" is "itemTypeMeatWeight".
>
> Do you know how to solve this problem?
>
> Thanks in advance.
>
> Pau
>
> _______________________________________________________________________
>
> XML-DEV is a publicly archived, unmoderated list hosted by OASIS
> to support XML implementation and development. To minimize
> spam in the archives, you must subscribe before posting.
>
> [Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
> Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
> subscribe: xml-dev-subscribe@lists.xml.org
> List archive: http://lists.xml.org/archives/xml-dev/
> List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
>
_______________________________________________________________________
XML-DEV is a publicly archived, unmoderated list hosted by OASIS
to support XML implementation and development. To minimize
spam in the archives, you must subscribe before posting.
[Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
subscribe: xml-dev-subscribe@lists.xml.org
List archive: http://lists.xml.org/archives/xml-dev/
List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]