Using XMLValidatingReader

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
 
M

Martin Honnen

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top