I'm trying to figure out exactly what's going wrong with an xpath
keyref validation scenario.
In brief, I have something like the following in my xsd:
<xs:schema>
<xs:complexTy pe name="topLevelC ontainer">
<!-- define an element -->
<xs:complexTy pe name="element">
...
<xs:attribute name="id" type="xs:int" use="required"/>
</xs:complexType>
<!-- instance one, simple list -->
<xs:element name="instanceO ne" minOccurs="0">
<xs:sequecne>
<xs:element name="elementDe scription" type="element"
minOccurs="0" maxOccurs="unbo unded"/>
</xs:sequence>
</xs:complexType>
<!-- instance two, an inner, heterogenous list -->
<xs:complexTy pe name="instanceT wo" type="anotherTy pe">
<xs:element name="elementLi st">
<xs:complexType >
<xs:choice maxOccurs="unbo unded">
<xs:complexTy pe name="fullEleme nt"
type="elementTy pe"/>
<xs:complexTy pe name="elementRe f" type="xs:int"/>
</xs:choice>
</xs:complexType>
</xs:sequence>
<!-- constraints -->
<!-- key points to the id attribute of instanceOne type -->
<xs:key name="elementKe y">
<xs:selector xpath="instance One/elementDescript ion"/>
<xs:field xpath="@id">
</xs:key>
<!-- keyref points to more-deeply nested instanceTwo type -->
<xs:keyref name="elementRe f" refer="elementK ey">
<xs:selector xpath="instance Two/elementList/elementRef"/>
<xs:field xpath="."/>
</xs:keyref>
</xs:complexType> <!-- end top-level container -->
</xs:schema>
In short, what I am trying to do is ensure that the references from
within the instanceTwo type point to elements within the instanceOne
type. But what I'm not able to figure out is how to enforce that the
instanceTwo type contain references to fully described elements in
instanceOne only. For some reason, a file will validate when the
references out of instanceTwo refer to elementDescript ions from other
instanceTwos in the file.
I'm suspicious that the xpath comparison will never return false for
some reason related to datatype. (My xml editor seems to suggest that
the xpath expressions are returning the appropriate values.)
???