i have this xsd
<xs:schema version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="foo">
<xs:complexType>
<xs:choice>
<xs:element name="bar"
minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="id"
use="required"
type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="batz"
minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="idref"
use="required"
type="xs:string" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:key name="ID">
<xs:selector xpath="./bar" />
<xs:field xpath="@id" />
</xs:key>
<xs:keyref name="IDREF" refer="ID">
<xs:selector xpath="./batz" />
<xs:field xpath="@idref" />
</xs:keyref>
</xs:element>
</xs:schema>
and i have these two xml which are using this xsd as a validaion:
first
<?xml version="1.0" encoding="UTF-8"?>
<foo xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation=
'file:/home/tareq/NetBeansProjects/HTML5Application/public_html/refTest.xsd'>
<bar id="1"/>
<bar id="2"/>
</foo>
second:
<?xml version="1.0" encoding="UTF-8"?>
<foo xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation =
'file:/home/tareq/NetBeansProjects/HTML5Application/public_html/refTest.xsd'>
<batz idref="1" /> <!-- this should succeed because <bar id="1"> exists -->
<batz idref="3" /> <!-- this should FAIL -->
</foo>
the validation says error and works correctly when i replace the choice tag with a sequence tag and i write the two xml in one xml.
the problem appears in this xsd, i mean two xml can't be ref/keyref between each others.
that's what i'm facing right now and that's what i'm trying to do since 3 days.
If I understand you correctly, you want to use XSD key and keyref to check (a) that values in one XML document are unique within that document (using xsd:key) and (b) that values in another XML document are drawn only from the values given in the first document (using xsd:keyref).
Goal (a) is achievable; goal (b) is not achievable with XSD. XSD's referential integrity constraints are intended for use within a single XML document, not across document boundaries. To check integrity constraints across document boundaries, you can use the W3C's Service Modeling Language (which essentially is intended to extend XSD with some cross-document integrity checking of this kind) or Schematron. Good luck.