This object is a Microsoft extension to the W3C DOM.
The ParseError object returns detailed information about the last error.
To demonstrate this the following simple XML file 'states.xml' is used where the slash
in the closing 'capital' tag of the first State element (Florida) has been deliberately
omitted.
<States>
<State ref="FL">
<name>Florida</name>
<capital>Tallahassee<capital>
</State>
<State ref="IA">
<name>Iowa</name>
<capital>Des Moines</capital>
</State>
</States>
The following 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:
Code (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
The following appears in the Message Box:
Output:
Parse Error line 7, character 32
<capital>Tallahassee<capital>
PROPERTIES
errorCode Property
This property contains the error code of the last parse error.
Syntax: ParseError.errorCode
filepos Property
This property contains the absolute file position where the error occurred.
Syntax: ParseError.filepos
line Property
This property returns the number of the line that contains the parse error.
Syntax: ParseError.line
linepos Property
This property contains the position of the character within the line where the parse
error occurs.
Syntax: ParseError.linepos
reason Property
This property returns a string detailing the reason for the error.
Syntax: ParseError.reason
srcText Property
This property returns the full text of the line containing the error as a string.
Syntax: ParseError.srcText
url Property
This property contains the URL of the XML document containing the last error.
Syntax: ParseError.url
|