Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML DOM Parse Error Object

XML DOM Parse Error Object


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

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


The parseError object

A parser error (parser-error) can occur when you try to open an XML document.

Through 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 (File Error)

In the code below, we will try to load a file that does not exist and display some 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 »


XML Error (XML Error)

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

(You can read more in our XML Tutorialabout well-formed and valid XML.)

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 »

View the 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 document being loaded.
filepos Returns a long integer file position of the error.