Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XML DOM Parse Error object


May 27, 2021 XML DOM


Table of contents


XML DOM Parse Error object


Microsoft's parseError object can be used to get the error message back from Microsoft's XML analyzer.

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


ParseError object

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

With this parseError object, you can get back error codes, error text, lines that cause errors, and so on.

Note: The parseError object does not belong to the W3C DOM standard!


File Error

In the following code, we try to load a file that doesn't exist and display some error properties:

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 out . . .

XML Errors (XML Error)

In the following code, we'll have the parser load a poorly formed XML document.

(You can read more about good and effective XML in our XML tutorial.)

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 out . . .

View XML files: note_error.xml


The properties of the parseError object

属性 描述
errorCode 返回一个长整数错误代码。
reason 返回一个字符串,包含错误的原因。
line 返回一个长整数,代表错误的行号。
linepos 返回一个长整数,代表错误的行位置。
srcText 返回一个字符串,包含引起错误的行。
url 返回指向被加载文档的 URL。
filepos 返回错误的一个长整型文件位置。