Altova Mailing List Archives>Archive Index >xmlschema-dev Archive Home >Recent entries >Thread Prev - >Thread Next - Re: An element with more than one possible type An element with more than one possible typeTo: xmlschema-dev@--.--- Date: 2/2/2007 1:47:00 PM I am trying to code a XML Schema (XSD file) for a web service in such a way: <items> <item name = "pen" color ="22"> <item name = "pencil" smoothness = "10" > </items> It is to say, if name is "pen" , then use the "color" attribute. When name is "pencil" then use "smoothness" 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="pen"/> <xs:enumeration value="pencil"/> </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 "pencil": <xs:complexType name="itemTypePencil"> <xs:complexContent> <xs:restriction base="itemType"> <xs:attribute name = "name" type = "nameType" fixed="pencil"/> </xs:restriction> </xs:complexContent> </xs:complexType> .... and finally I added an attribute "smoothness": <xs:complexType name="itemTypePencilSmoothness"> <xs:complexContent> <xs:extension base="itemTypePencil"> <xs:attribute name = "smoothness" type = "xs:int"/> </xs:extension> </xs:complexContent> </xs:complexType> For the "pen" is the same as "pencil". First I restricted the "name" attribute to "pen": <xs:complexType name="itemTypePen"> <xs:complexContent> <xs:restriction base="itemType"> <xs:attribute name = "name" type = "nameType" fixed="pen"/> </xs:restriction> </xs:complexContent> </xs:complexType> .... and finally I added the "color" attribute <xs:complexType name="itemTypePenColor"> <xs:complexContent> <xs:extension base="itemTypePen"> <xs:attribute name = "color" 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="itemTypePenColor"/> <xs:element name="item" type="itemTypePencilSmoothness"/> </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 (itemTypePenColor). If I change the declaration of "item" element then the validator assumes that the type of "item" is "itemTypePencilSmoothness". Do you know how to solve this problem? Thanks in advance. Pau From boris@k... Sat Feb 03 07:59:13 2007 Received: from aji.w3.org ([133.27.228.225]) by frink.w3.org with esmtp (Exim 4.50) id | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
