XML Schema: disjunctive attributes for element possible ?

Gehirnloser Zombie

Usenet Archive
Joined
Jan 12, 2004
Messages
2
Reaction score
0
Hello folks,

Short question: Is it possible to express with XML-Schema that for an element some attributes may apear only disjunctivly (i.e. an element <E> can either carry the attribute "a1" OR "a2", but never both of them)?

Thanks in advance,

Puck.
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Gehirnloser said:
Short question: Is it possible to express with XML-Schema that for an element some attributes may apear only disjunctivly (i.e. an element <E> can either carry the attribute "a1" OR "a2", but never both of them)?

I know one way to do that, by defining a base type and deriving two types from and then use xsi:type on the instance data:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test20040112Xsd.xml"> <element xsi:type="elType1" a1="value" /> <element xsi:type="elType2" a2="value" /> </root>

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="element" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="element" type="elType" />

<xs:complexType name="elType" />

<xs:complexType name="elType1">
<xs:complexContent>
<xs:extension base="elType">
<xs:attribute name="a1" type="xs:string" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="elType2">
<xs:complexContent>
<xs:extension base="elType">
<xs:attribute name="a2" type="xs:string" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

</xs:schema>

I don't think you can do it without xsi:type.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,802
Members
249,594
Latest member
henrywalsh

Latest Threads

Top