This property is a Microsoft extension to the W3C DOM.
ParseError.srcText
The srcText property is read-only and returns the full text of the line containing
the error as a string. It returns an empty string if the error is because of XML that is not
well-formed, and cannot be pinned down to a specific line.
In the following example the file 'currencies.xml' is loaded which includes an error: the
slash character (/) is missing from the closing tag of the fourth 'currency' element.
If a parse error occurs, as it does in this case, an alert displays the number of the line
where it occurs, and the complete text of that line.
Note:
Where no parse error occurs, the errorCode
property returns 0.
XML:
<currencies>
<currency>CHF Swiss Francs</currency>
<currency>DEM German Deutsche Marks</currency>
<currency>GBP United Kingdom Pounds</currency>
<currency>JPY Japanese Yen<currency>
<currency>USD United States Dollars</currency>
</currencies>
Code (JavaScript):
xml_doc = new ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.load("currencies.xml");
err = xml_doc.parseError;
if (err.errorCode != 0)
alert("Error on line " + err.line + "\n" + err.srcText);
The alert displays the following message:
Output:
Error on line 8
<currency>JPY Japanese Yen<currency>
|