How to validate XML using a set of XSD files in C#?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I have a set of XSD schema files. They are inter-related. A master file A defines the root element, and it includes file B, C, D. B includes E and F, and so on.
How do I validate a XML file against this set of schemas?
I used following code:
<pre class="prettyprint foreach (string strXsdFilePath in Directory.GetFiles(strFolder, "*.xsd"))
m_xmlRdrSettings.Schemas.Add(null, strXsdFilePath);
m_xmlRdrSettings.ValidationType = ValidationType.Schema;
XmlReader rdr = XmlReader.Create(new StringReader(xmlDoc.InnerXml), m_xmlRdrSettings); [/code]
I have a validated XML file. If I add an invalid attribute, XML Spy can find out and throw validation error, but the above code will just pass validation.
Please help!
<br/>

View the full article
 
Back
Top