Hi
I have a question
whether XmlValidatingReader doesn't check keyref constrain (the same with
key constraint) or I do smth wrong.
I have the following schema
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="module" targetNamespace="http://tempuri.org/module.xsd"
xmlns="http://tempuri.org/module.xsd"
xmlns:mstns="http://tempuri.org/module.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="module">
<xs:complexType>
<xs:sequence>
<xs:sequence>
<xs:element ref="type" maxOccurs="unbounded" />
<xs:element ref="object" maxOccurs="unbounded" />
</xs:sequence>
</xs:sequence>
</xs:complexType>
<xs:key name="typeNameKey">
<xs:selector xpath=".//type" />
<xs:field xpath="@name" />
</xs:key>
<xs:key name="objectNameKey">
<xs:selector xpath=".//object" />
<xs:field xpath="@name" />
</xs:key>
<xs:keyref name="typeOfObject" refer="typeNameKey">
<xs:selector xpath=".//object" />
<xs:field xpath="@ofType" />
</xs:keyref>
</xs:element>
<xs:element name="type">
<xs:complexType>
<xs:sequence />
<xs:attribute name="name" type="xs:NMTOKEN" />
</xs:complexType>
</xs:element>
<xs:element name="object">
<xs:complexType>
<xs:sequence />
<xs:attribute name="name" type="xs:NMTOKEN" />
<xs:attribute name="ofType" type="xs:NMTOKEN" />
</xs:complexType>
</xs:element>
</xs:schema>
and read the file
<?xml version="1.0" encoding="utf-8" ?>
<module xmlns="http://tempuri.org/module.xsd">
<type name="A" />
<type name="B" />
<object name="o1" ofType="A" />
<object name="o2" ofType="A" />
<object name="o3" ofType="B" />
<object name="o4" ofType="B" />
<object name="o4" ofType="C" />
</module>
with the code
XmlTextReader reader = new XmlTextReader(@"../../module1.xml");
XmlValidatingReader vreader = new XmlValidatingReader(reader);
vreader.Schemas.Add(@"http://tempuri.org/module.xsd",
@"../../module.xsd");
vreader.ValidationType = ValidationType.Schema;
vreader.ValidationEventHandler += new
ValidationEventHandler(vreader_ValidationEventHand ler);
XmlDocument doc = new XmlDocument();
doc.Load(vreader);
But I don't get an error for <object name="o4" ofType="C" />.
So the question is whether XmlValidatingReader doesn't check keyref
constrain (the same with key constraint) or I do smth wrong.
Dima.