"David" <ca*******@wall a.com> wrote in message news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
How do I use this xsd file to valid the string?
using System;
using System.IO;
using System.Xml;
using System.Xml.Sche ma;
// . . .
private bool isSchemaValid;
// . . .
private void btnValidate_Cli ck( object sender, EventArgs args)
{
// . . .
this.isSchemaVa lid = true;
string targetNamespace URI = "urn:your-schema-com"; // put the target namespace URI of your schema here.
XmlValidatingRe ader reader = new XmlValidatingRe ader( new XmlTextReader( new StringReader( xml_string ) ) );
reader.Schemas. Add( targetNamespace URI, "schema.xsd ");
reader.Validati onEventHandler += new ValidationEvent Handler( xmlDocument1_Va lidationCallBac k);
XmlDocument xmlDocument1 = new XmlDocument( );
xmlDocument1.Lo ad( reader); // this will call Read( ) on the XmlValidatingRe ader, which schema-validates as it loads.
// . . .
// . . . any schema errors will result in the callback method being called while Load( ) processes.
// . . .
Console.WriteLi ne( "\r\n\tSchemaVa lid = " + this.isSchemaVa lid.ToString( ) );
// . . .
}
// . . .
private void xmlDocument1_Va lidationCallBac k( object sender, ValidationEvent Args args)
{
isSchemaValid = false;
Console.WriteLi ne( "\r\n\tValidati on Error: " + args.Message );
}
Derek Harmon