DonDiesl
DonDiesl

Reputation: 31

Referencing multiple IDs in an XML schema (XSD)

I was wondering whether it's possible to differentiate between ID fields in an XML schema. I'm having the following schema:

<element name="define_apple">
    <complexType>
        <attribute name="colour" type="ID"/>
    </complexType>
</element>

<element name="define_orange">
    <complexType>
        <attribute name="colour" type="ID"/>
    </complexType>
</element>

<element name="reference_apple">
    <complexType>
        <attribute name="colour" type="IDREF"/>
    </complexType>
</element>

<element name="reference_orange">
    <complexType>
        <attribute name="colour" type="IDREF"/>
    </complexType>
</element>

However, the references are not uniquely linked to the respective definitions. I can still write the following nonsense but valid XML:

<define_apple colour="green"/>
<define_orange colour="orange"/>

<reference_apple colour="orange"/>
<reference_orange colour="green"/>

Is there a way to link the fields correctly using ID and IDREF, for instance using namespaces? I know I could just use key and keyref, but the ID thing is a bit more appealing to me.

Upvotes: 3

Views: 1572

Answers (1)

a3nm
a3nm

Reputation: 8884

No, I don't think this is possible. http://www.w3.org/TR/xmlschema-2/#ID and http://www.w3.org/TR/xmlschema-2/#IDREF say that the ID and IDREF attributes types come from the XML standard, and http://www.w3.org/TR/2000/WD-xml-2e-20000814#NT-TokenizedType says that the validity constraints on IDREF is only to match some ID in the document. I guess ID and IDREF are mostly in XML Schema for backwards compatibility with DTDs.

Upvotes: 1

Related Questions