Latest web development tutorials

XML DOM Parse Error Object

Microsoft parseError object can be used to retrieve the error message from the Microsoft XML parser.

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


parseError objects

When you try to open an XML document, it is a parser error (parser-error) may occur.

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

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


File Error (File Error)

In the code below, we will try to load a nonexistent file, and display some error properties:

Examples

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 following code, we will let the parser to load a bad form of XML documents.

(You can in our XML tutorial Read more about the good and effective form of XML.)

Examples

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"

See XML file: note_error.xml


Object attributes parseError

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