Greetings all.
Is it possible to create a schema to enforce the following issue.
If the value for required Attribute A within Element E has an enumerated
value of ‘myType’ then element E also needs to have Attribute B.
Xml example below
E=Item
A=type
B=len
<Items>
<Item type=” myType” len=”5” />
<Item type=” NOTmyType” />
</Items>
Any help or a point in a semi right direction would be very helpful :)
> Is it possible to create a schema to enforce the following issue.
>
[quoted text clipped - 10 lines]
> <Item type=” NOTmyType” />
> </Items>
No, you can't put constraints on one attribute based on the value of
another attribute, not with the W3C XSD schema language.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
AdamH - 25 Apr 2006 18:58 GMT
was afraid of that.
thanks for the validation :)
is it then common practice to have different node names to start with, and
not differentiate by node type?
> > Is it possible to create a schema to enforce the following issue.
> >
[quoted text clipped - 13 lines]
> No, you can't put constraints on one attribute based on the value of
> another attribute, not with the W3C XSD schema language.
Hi Adam,
XML Schema allows you to specify the type of an element in the instance
using the schema instance type attribute, xsi:type. Here it is a sample
schema and a valid instance that shows that.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Items">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element ref="Item"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Item" type="AbstractItemType"/>
<xs:complexType name="AbstractItemType" abstract="true"/>
<xs:complexType name="myType">
<xs:complexContent>
<xs:extension base="AbstractItemType">
<xs:attribute name="len" type="xs:integer"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="NOTmyType">
<xs:complexContent>
<xs:extension base="AbstractItemType">
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
<Items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Item xsi:type="myType" len="5"/>
<Item xsi:type="NOTmyType"/>
</Items>
Hope that helps,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
AdamH - 26 Apr 2006 16:07 GMT
hmmmm good food for thought. Thank you.
gotta take a closer look at this and see if i can make it fit our needs.
btw i love it when the answer takes you on a ride of exploration and for
that i really thank you :)
> Hi Adam,
>
[quoted text clipped - 39 lines]
> <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
> http://www.oxygenxml.com