XML Schema - element of type "list" as an IDREFS

432 Views Asked by At

I would to create a list of references (like an element of IDREFS type) using key and keyref, so that each item in my list (Links in the example below) refers the attribute @name of a Link.

The code below do not works, but I would to write something like that:

<xs:element name="root">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Node">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="Links">
                        <xs:simpleType>
                            <xs:list itemType="xs:string" />
                        </xs:simpleType>
                        <xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="Link">
            <xs:complexType>
                <xs:attribute type="xs:string" name="name" use="required" />
                <xs:attribute type="xs:string" name="source" use="required" />
                <xs:attribute type="xs:string" name="destination" use="required" />
            </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:key name="LinkKey">
        <xs:selector xpath="Link" />
        <xs:field xpath="@name" />
    </xs:key>
    <xs:keyref name="LinkRef" refer="LinkKey">
        <xs:selector xpath="Node" />
        <xs:field xpath="Links" />
    </xs:keyref>
<xs:element>

instead of:

<xs:element name="root">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Node">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="Links" type:"xs:IDREFS" />
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="Link">
            <xs:complexType>
                <xs:attribute type="xs:ID" name="name" use="required" />
                <xs:attribute type="xs:string" name="source" use="required" />
                <xs:attribute type="xs:string" name="destination" use="required" />
            </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
<xs:element>

Is it possible?

1

There are 1 best solutions below

0
Michael Kay On

No, this isn't possible using key and keyref. You would need to use XSD 1.1 assertions.