The parseError Object

The parseError object returns information about the last parse error. To demonstrate how the parseError object works, we need to use an XML document with an error in it. Code Listing A-1a (AppxA\LstA_1a.xml on the companion CD) is the email document with the Cc and Bcc elements reversed, which is an error according to the DTD.

Code Listing A-1a.

<?xml version="1.0"?>

<!DOCTYPE EMAIL SYSTEM "LstA_2.dtd">
<EMAIL PRIORITY="HIGH">
  <TO>Jodie@msn.com</TO>
  <FROM>Bill@msn.com</FROM>
  <BCC>Naomi@msn.com</BCC>
  <CC>Philip@msn.com</CC>
  <SUBJECT>My document is a tree.</SUBJECT>
  <BODY>This is an example of a tree structure.</BODY>
</EMAIL>

parseError Object Properties

The list below shows the properties available for the parseError object:

The errorCode Property

Returns the error code of the last parse error.

Basic Syntax intErrorValue = xmlDocument.parseError.errorCode;
Details Returns a long integer. This property is read-only.

Usage Example The following example can be found in AppxA\LstA_66.htm on the companion CD:

intParseValue = xmlDoc.parseError.errorCode;
alert(intParseValue);

The filePos Property

Returns the position in the file where the error occurred.

Basic Syntax intErrorValue = xmlDocument.parseError.filePos;
Details Returns a long integer representing the absolute position (in number of characters) of the error. This property is read-only.

Usage Example The following example can be found in AppxA\LstA_67.htm on the companion CD:

intParseValue = xmlDoc.parseError.filePos;
alert(intParseValue);

The line Property

Returns the line number where the error occurred.

Basic Syntax intErrorValue = xmlDocument.parseError.line;
Details Returns a long integer representing the line number where the error occurred. This property is read-only.

Usage Example The following example can be found in AppxA\LstA_68.htm on the companion CD:

intParseValue = xmlDoc.parseError.line;
alert(intParseValue);

The linePos property

Returns the position in the line where the error occurred.

Basic Syntax intErrorValue = xmlDocument.parseError.linePos;
Details Returns a long integer representing the character position in the line where the error occurred. This property is read-only.

Usage Example The following example can be found in AppxA\LstA_69.htm on the companion CD:

intParseValue = xmlDoc.parseError.linePos;
alert(intParseValue);

The reason Property

Returns the reason for the last parse error.

Basic Syntax strErrorReason = xmlDocument.parseError.reason;
Details Returns a string containing a description of the reason for the last parse error. This property is read-only.

Usage Example The following example can be found in AppxA\LstA_70.htm on the companion CD:

strErrorReason = xmlDoc.parseError.reason;
alert(strErrorReason);

The srcText Property

Returns the text of the line containing the error.

Basic Syntax strSrcText = xmlDocument.parseError.srcText;
Details Returns a string containing the full text of the line that contains the error, including white space. This property is read-only.

Usage Example The following example can be found in AppxA\LstA_71.htm on the companion CD:

strSrcText = xmlDoc.parseError.srcText;
alert(strSrcText);