Reputation: 3307
I use globally unique identifier (GUID) for my xml elements, schema looks like this:
<xs:simpleType name="guidType">
<xs:restriction base="xs:string">
<xs:pattern value="[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]
{4}-[a-fA-F0-9]{12}"/>
</xs:restriction>
</xs:simpleType>
and xml element like this:
<point guid="5C815FB2-0731-4E88-9885-CFC49B8E7B92" id="ABC" x="12" y="51" z="0"/>
Corresponding xsd schema:
<xs:complexType name="pointType">
<xs:attribute name="guid" type="guidType" use="required"/>
<xs:attribute name="id" type="xs:token" use="required"/>
<xs:attribute name="x" type="xs:double" use="required"/>
<xs:attribute name="y" type="xs:double" use="required"/>
<xs:attribute name="z" type="xs:double" use="required"/>
</xs:complexType>
I would like to reference my point element in another element, e.g.:
<layer>
<pointref guidref="5C815FB2-0731-4E88-9885-CFC49B8E7B92"/>
<pointref guidref="4671EFD4-506F-4A61-BCF0-427875074115"/>
</layer>
I could achieve it using ID and IDREF types changing my point type definition in schema file:
<xs:attribute name="guid" type="xs:ID" use="required"/>
Question:
Is there any way to make xs:ID type to be of type GUID too ?
Upvotes: 2
Views: 2128
Reputation: 21638
Short answer is no. IDs are NCNAMEs, so a value with a digit in the first position would ruin it. While it may seem a bit more involved, using xsd:unique/xsd:key/xsd:keyref is considered by many the best way to achieve what you want when using XSD.
Just in case you might need a reference, you could start right here on SO.
Upvotes: 3