David Thielen wrote:
Yes it is .NET 2.0. And I realized last night that XmlDocument is creating a
DOM and I'd prefer to avoid that overhead. I just want it to read through and
then discard the document so a SAX reader is fine.
..NET has no SAX push parser but has a pull parser with XmlReader, here
is an example on how to that with .NET 2.0 if you want to validate
against a DTD, the example aborts parsing if an error is found:
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.ProhibitDtd = false;
readerSettings.ValidationType = ValidationType.DTD;
XmlReader xmlReader = XmlReader.Create(@"example.xml", readerSettings);
bool valid = true;
bool moreNodes = true;
do {
try {
moreNodes = xmlReader.Read();
}
catch (XmlException e) {
valid = false;
Console.WriteLine(
"Parse error \"{0}\" at line {1}, position {2}.", e.Message,
e.LineNumber, e.LinePosition);
}
catch (XmlSchemaValidationException se) {
valid = false;
Console.WriteLine(
"Validation error \"{0}\" at line {1}, position {2}.", se.Message,
se.LineNumber, se.LinePosition);
}
}
while (valid && moreNodes);
if (valid) {
Console.WriteLine("No errors found during XML parsing.");
}
Alternatively if you wanted to continue parsing to report all errors you
need a ValidationEventHandler, see the documentation of the
XmlReaderSettings class in your SDK documentation or online here:
<http://msdn2.microsoft.com/en-us/library/system.xml.xmlreadersettings(VS.80).aspx>
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/