I load a XMLDocument with some XML, then I select particular node, which I would like to validate.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Schemas.Add(null, @"C:\Documents and Settings\ajoksimovic\My Documents\Visual Studio 2005\Projects\ConsoleApplication7\ConsoleApplicati on7\XMLSchema1.xsd");
xmlDoc.Load(@"C:\aco.xml");
xmlTemplateList = xmlDoc.DocumentElement.SelectNodes("//template");
Schema is
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1" targetNamespace="http://tempuri.org/XMLSchema1.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema1.xsd" xmlns:mstns="http://tempuri.org/XMLSchema1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="template">
<xs:complexType mixed="true">
<xs:sequence>
<xs:any minOccurs="0" />
</xs:sequence>
<xs:attribute name="datatableID" type="xs:unsignedInt" />
</xs:complexType>
</xs:element>
</xs:schema>
so each node in xmlTemplateList should validate against this schema, XMLDocument has overload for Validate
public void Validate(ValidationEventHandler validationEventHandler, XmlNode nodeToValidate); So i tried
xmlDoc.Validate(null,xmlTemplateList[0]) but it does not work in my case.
Last edited by joxa83; January 9th, 2009 at 08:20 AM..
|