Using XMLValidatingReader

  • Thread starter Thread starter JoeZ
  • Start date Start date
J

JoeZ

Hi all,

I have a question about using XMLValidatingReader.

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,
XMLValidatingReader always complains. If schema file path is included, then
it doesn't complain.

Is there any way to tell XMLValidatingReader where the schema file is, or am
I missing anything?

TIA,

JoeZ
 
JoeZ said:
I have a question about using XMLValidatingReader.

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,
XMLValidatingReader always complains. If schema file path is included, then
it doesn't complain.

Is there any way to tell XMLValidatingReader where the schema file is, or am
I missing anything?

First of all, with .NET 2.0 you should not use XmlValidatingReader for
XSD schema validation, rather use an XmlReader with the proper
XmlReaderSettings e.g.
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.ValidationType = ValidationType.Schema;
readerSettings.Schemas.Add(null, "schema.xsd");
readerSettings.ValidationEventHandler += delegate (object sender,
ValidationEventsArgs vargs) {
Console.WriteLine("{0}: {1}", vargs.Severity, vargs.Message);
};
using (XmlReader reader = XmlReader.Create("file.xml", readerSettings))
{
while (reader.Read()) {}
}

If you use .NET 1.1 then you need XmlValidatingReader for validation but
you can set the schema(s) similar to the above code.
 
Back
Top