XML DOM Parse ErrorObject


Microsoft's parseError object can be used to retrieve error information from Microsoft's XML parser.

To see how Firefox handles parser errors, please see the next page of this tutorial.


parseError object

When you attempt to open an XML document, a parser-error may occur.

Via this parseError object, you can retrieve the error code, error text, the line that caused the error, and so on.

Note:The parseError object is not part of the W3C DOM standard!


File Error

In the code below, we will attempt to load a non-existent file and display certain error properties:

Example

xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("ksdjf.xml");

document.write("Error code: " + xmlDoc.parseError.errorCode);
document.write("
Error reason: " + xmlDoc.parseError.reason);
document.write("
Error line: " + xmlDoc.parseError.line);

Try it Yourself »

XML Error (XML Error)

In the code below, we will have the parser load a malformed XML document.

(You can on ourXML Tutorialread more about well-formed and valid XML in...)

Example

xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("note_error.xml");

document.write("Error code: " + xmlDoc.parseError.errorCode);
document.write("
Error reason: " + xmlDoc.parseError.reason);
document.write("
Error line: " + xmlDoc.parseError.line);

Try it Yourself »

View XML file:note_error.xml


Properties of the parseError object

Property Description
errorCode Returns a long integer error code.
reason Returns a string containing the cause of the error.
line Returns a long integer representing the line number of the error.
linepos Returns a long integer representing the line position of the error.
srcText Returns a string containing the line that caused the error.
url Returns the URL pointing to the loaded document.
filepos Returns a long integer file position of the error.

other extensions