XML DOM » ParseError » reason

Compability: Internet Explorer

Syntax:
parseError.reason

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

Validation errors also include the URL of the Schema and the node within the Schema that corresponds to the error.

Examples

Code:
XML:

<staff>
   <employee ssn="123456" pay="3">
      <name>John Sullivan</name>
      <position>senior executive</position>
   </employee>
   <employee>
      <name>Mary Lopez</name>
      <position>personal assistant</position>
   </employee>
</staff>

VBScript:

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("staff.xml")
Set ParseErr = objXMLDoc.parseError
If ParseErr.errorCode <> 0 Then
   alert("Error on Line: " & ParseErr.line & vbCrLf & ParseErr.reason)
End If
Output:
Error on Line: 10
Element content is invalid according to the DTD/Schema.
Expecting: #PCDATA
Explanation:

In this example example the file 'staff.xml' is loaded which includes an error: the second employee element does not include an 'ssn' attribute which is required by the DTD. If a parse error occurs, as it does in this case, an alert displays the number of the line where it occurs, and the reason why.

Language(s): VBScript XML