XmlDocument Load-Time Validation
You can validate XML documents as they are loaded by using the Load method to load the XmlDocument with an XmlValidatingReader.
The following code example shows the XmlDocument, doc
, loading an XmlValidatingReader, reader
, as input.
Dim doc as XmlDocument = new XmlDocument()
Dim tr as XmlTextReader = new XmlTextReader("Sample.xml")
Dim reader as XmlValidatingReader = new XmlValidatingReader(tr)
doc.Load(reader)
[C#]
XmlDocument doc = new XmlDocument();
XmlTextReader tr = new XmlTextReader("Sample.xml");
XmlValidatingReader reader = new XmlValidatingReader(tr);
doc.Load(reader);