XML Schema Validation

  • Thread starter Thread starter Rahul Aggarwal
  • Start date Start date
R

Rahul Aggarwal

Hi,

How can you validate an xml document against a schema in c#.

Thanks
Rahul
 
Of course, it goes somehting like this:

String xmlFrag = "<author xmlns='urn:bookstore-schema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
"<first-name>Herman</first-name>" +
"<last-name>Melville</last-name>" +
"</author>";

XmlParserContext context = new XmlParserContext(null, null, "",
XmlSpace.None);

reader = new XmlValidatingReader(xmlFrag, XmlNodeType.Element, context);
myschema.Add("urn:bookstore-schema", "c:\\Books.xsd");

reader.ValidationType = ValidationType.Schema;
reader.Schemas.Add(myschema);

while (reader.Read())
{
}
 
Back
Top