Sunday, 10 August 2014

xsd: attribute points to element id



I have an xml describing vertices on a directed graph:



<graph>
<vertex id="a">
<edge target="b">
</vertex>
<vertex id="b"/>
</graph>


Given the schema:



<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://ift.tt/tphNwY">

<xs:complexType name="vertex">
<xs:sequence>
<xs:element type="edge" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="id" use="required" type="xs:string"/>
</xs:complexType>

<xs:complexType name="edge">
<xs:attribute name="target" use="required"/>
</xs:complexType>

<xs:complexType name="graph">
<xs:sequence>
<xs:element name="vertex" type="vertex" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="crawl-job" type="crawl-jobType"/>
</xs:schema>


How can I modify the target attribute so it's value can only be valid vertex id's?


so my initial example is a valid xml but:



<graph>
<vertex id="a">
<edge target="c">
</vertex>
<vertex id="b"/>
</graph>


is not.


No comments:

Post a Comment