Quickly validating an XML document against an XML Schema

T

TP-Software

Hi,

What's the fastest way to validate an XML document against an XML Schema?
All I need to know is wether or not the document is valid in respect to the
Schema

Could someone show me an example in C# ?

Thnx.
 
S

Steven Wood

TP-Software said:
Hi,

What's the fastest way to validate an XML document against an XML Schema?
All I need to know is wether or not the document is valid in respect to the
Schema

XmlTextReader reader = new XmlTextReader(fileName);
XmlValidatingReader vReader = new XmlValidatingReader(reader);

vReader.ValidationType = ValidationType.Schema;

try
{
while(vReader.Read());
}
catch
{
// error
}

If the schema is not in the XML file, you can use:

vReader.Schemas.Add(...) to add a reference to the schema.
 

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