I tried to valid two XML files: One file file1.xml has a element with an xs:ID type attribute and in the other file2.xml has an element with an xs:IDREF type attribute and for validate that, i use a file.xsd.
this is my try:
<!-- file1.xml -->
<book id="l1">
<title>El señor de los anillos</title>
<author>J.R.R. Tolkien</author>
</book>
<!-- file2.xml -->
<review ref="l1">
<comment>Un clásico de la literatura</comment>
<score>5</score>
</review>
<!-- file.xsd -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- book -->
<xs:element name="book" type="bookType">
</xs:element>
<!-- review -->
<xs:element name="review" type="reviewType">
<xs:unique name="bookID" >
<xs:selector xpath="book"/>
<xs:field xpath="@id"/>
</xs:unique>
<xs:keyref name="reviewRef" refer="bookID">
<xs:selector xpath="review"/>
<xs:field xpath="@ref"/>
</xs:keyref>
</xs:element>
<!-- book -->
<xs:complexType name="bookType">
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
<!-- review -->
<xs:complexType name="reviewType">
<xs:sequence>
<xs:element name="comment" type="xs:string"/>
<xs:element name="score" type="xs:integer"/>
</xs:sequence>
<xs:attribute name="ref" type="xs:IDREF" use="required"/>
</xs:complexType>
</xs:schema>
Try to see the xmlschema documentation but the only thing I could do is this:
from xmlschema import XMLSchema
schema = XMLSchema('file.xsd')
schema.validate('file1.xml')
schema.validate('file2.xml')