Hi
I have a question
whether XmlValidatingRe ader 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="ht tp://tempuri.org/module.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata">
<xs:element name="module">
<xs:complexType >
<xs:sequence>
<xs:sequence>
<xs:element ref="type" maxOccurs="unbo unded" />
<xs:element ref="object" maxOccurs="unbo unded" />
</xs:sequence>
</xs:sequence>
</xs:complexType>
<xs:key name="typeNameK ey">
<xs:selector xpath=".//type" />
<xs:field xpath="@name" />
</xs:key>
<xs:key name="objectNam eKey">
<xs:selector xpath=".//object" />
<xs:field xpath="@name" />
</xs:key>
<xs:keyref name="typeOfObj ect" refer="typeName Key">
<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:NMTOKE N" />
</xs:complexType>
</xs:element>
<xs:element name="object">
<xs:complexType >
<xs:sequence />
<xs:attribute name="name" type="xs:NMTOKE N" />
<xs:attribute name="ofType" type="xs:NMTOKE N" />
</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");
XmlValidatingRe ader vreader = new XmlValidatingRe ader(reader);
vreader.Schemas .Add(@"http://tempuri.org/module.xsd",
@"../../module.xsd");
vreader.Validat ionType = ValidationType. Schema;
vreader.Validat ionEventHandler += new
ValidationEvent Handler(vreader _ValidationEven tHandler);
XmlDocument doc = new XmlDocument();
doc.Load(vreade r);
But I don't get an error for <object name="o4" ofType="C" />.
So the question is whether XmlValidatingRe ader doesn't check keyref
constrain (the same with key constraint) or I do smth wrong.
Dima.