JoeZ wrote:
I have a question about using XMLValidatingRe ader.
I have a schema files (xsd), and a xml data file. In the xml data file, if I
don't specify the schema file path,
XMLValidatingRe ader always complains. If schema file path is included, then
it doesn't complain.
Is there any way to tell XMLValidatingRe ader where the schema file is, or am
I missing anything?
First of all, with .NET 2.0 you should not use XmlValidatingRe ader for
XSD schema validation, rather use an XmlReader with the proper
XmlReaderSettin gs e.g.
XmlReaderSettin gs readerSettings = new XmlReaderSettin gs();
readerSettings. ValidationType = ValidationType. Schema;
readerSettings. Schemas.Add(nul l, "schema.xsd ");
readerSettings. ValidationEvent Handler += delegate (object sender,
ValidationEvent sArgs vargs) {
Console.WriteLi ne("{0}: {1}", vargs.Severity, vargs.Message);
};
using (XmlReader reader = XmlReader.Creat e("file.xml", readerSettings) )
{
while (reader.Read()) {}
}
If you use .NET 1.1 then you need XmlValidatingRe ader for validation but
you can set the schema(s) similar to the above code.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/