XML DOM » Objects » ParseError

The ParseError object returns detailed information about the last error.

Examples

Code:
XML:

<States>
   <State ref="FL">
      <name>Florida</name>
      <capital>Tallahassee<capital>
   </State>
   <State ref="IA">
      <name>Iowa</name>
      <capital>Des Moines</capital>
   </State>
</States>

VBScript:

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("states.xml")

If objXMLDoc.parseError.errorCode <> 0 Then
   MsgBox("Parse Error line " & objXMLDoc.parseError.line & ", character " &_
       objXMLDoc.parseError.linePos & vbCrLf & objXMLDoc.parseError.srcText)
End If
Output:
Parse Error line 7, character 32M
<capital>Tallahassee<capital>
Explanation:

This example checks for parse errors immediately after loading the XML file, and if there are any, displays a message box listing the line number, character position and text where it occurred:

Language(s): VBScript XML

Properties

errorCode

Syntax: parseError.errorCode

This property is read-only and contains the error code of the last parse error.

filepos

Syntax: parseError.filepos

This property contains the absolute file position where the error occurred.

line

Syntax: parseError.line

This property returns the number of the line that contains the parse error.

linepos

Syntax: parseError.linepos

This property contains the position of the character within the line where the parse error occurs.

reason

Syntax: parseError.reason

This property returns a string detailing the reason for the error.

srcText

Syntax: parseError.srcText

This property returns the full text of the line containing the error as a string.

url

Syntax: parseError.url

This property contains the URL of the XML document containing the last error.