I wish to create an XML document in which one of its elements must be defined with one of two known attributes, but not both.
For example, I would like to define a "webAddress" element as follows:
<xs:element name="webAddress">
<xs:complexType>
<xs:attribute name="hostName" type="xs:string"/>
<xs:attribute name="hostAddress" type="xs:string"/>
</xs:complexType>
</xs:element>
but I only want a user to be able to define either a hostName attribute (e.g., hostName= ") or a hostAddress (e.g., hostAddress="") attribute, but not both. It appears that the construct accomplishes this for elements. Is there a functional equivalent for attributes, or is there a better way to approach this?
If found that we can't do this with W3C XML Schema. We can use an embedded schematron rule but can we do it on choice element by checking element and attribute together? For example something like this:
<xs:choice>
<xs:element name="webAddress">
<xs:complexType>
<xs:attribute name="hostName" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="webAddress">
<xs:complexType>
<xs:attribute name="hostAddress" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:choice>
hostName
andhostAddress
should have the same rights – Nick<webAddress hostAddress="127.0.0.1"/>
or<webAddress webAddress="localhost"/>
but we can do this:<webAddress webAddress="localhost hostAddress="127.0.0.1""/>
– Nick