Mega Code Archive

 
Categories / C# Book / 06 XML
 

0563 Validating with an XmlReader

Here's how to plug a schema from the file customers.xsd into an XmlReader: using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Xml; using System.Xml.Linq; using System.Text; using System.IO; class Program { static void Main() { XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.Schema; settings.Schemas.Add(null, "customers.xsd"); XmlReader r = XmlReader.Create("customers.xml", settings); } }