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.