XML Schema: disjunctive attributes for element possible ?

G

Gehirnloser Zombie

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.
 
M

Martin Honnen

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.
 
G

Gehirnloser Zombie

Thanks, although the need to specify the "xsi:type" in the XML is not
an acceptable solution for me.

Puck.
 

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

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,006
Latest member
LauraSkx64

Latest Threads

Top