Looking for some sample codes in C#

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

JoeZ

Hi all,

I am looking for some sample codes in C#, in which, it can read a schema xsd
file and use it to validate an xml stream or file. Ideally the sample will
use XmlValidatingReader.

TIA,

JoeZ
 
Hi all,

I am looking for some sample codes in C#, in which, it can read a schema xsd
file and use it to validate an xml stream or file. Ideally the sample will
use XmlValidatingReader.

TIA,

JoeZ

Try this:
FileStream fs = File.Open("../../signatureinstance.xml",
FileMode.Open);
XmlTextReader reader = new XmlTextReader(fs);
XmlValidatingReader xvr = new XmlValidatingReader(reader);
xvr.ValidationType = ValidationType.Schema;
xvr.Schemas.Add(null, "../../signatureschema.xsd");
xvr.ValidationEventHandler += new
ValidationEventHandler(xvr_ValidationEventHandler);
XmlDocument xdoc = new XmlDocument();
xdoc.Load(xvr);

Courtesy of:
http://www.codeproject.com/useritems/XmlValidation.asp

Or, you could try here:
http://support.microsoft.com/kb/318504
 

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

Back
Top