DOMErrorHandling JScript example
The following JScript example attempts to load an invalid XML document. The parser encounters an error and uses xmlDoc.parseError.reason
to get the error message. For more information on other properties of the parseError
object, see IXMLDOMParseError Members, in XML DOM Reference.
Source Listing for DOMErrorHandling.js
Copy the data in the following listing. Save the file as DOMErrorHandling.js.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");
xmlDoc.async = false;
xmlDoc.load("books.xml");
if (xmlDoc.parseError.errorCode != 0)
{
WScript.Echo(xmlDoc.parseError.reason);
}
else
{
WScript.Echo(xmlDoc.documentElement.xml);
}
XML Data File (books.xml)
Copy the data from Resource: books.xml for DOMErrorHandling example and save it as books.xml, in the same directory where you saved DOMErrorHandling.js.
Output
When you run DOMErrorHandling.js, you should get the following error message:
End tag 'book' does not match the start tag 'review'.