XML DOM » ParseError » srcText

Compability: Internet Explorer

Syntax:
parseError.srcText

This property 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.

Examples

Code:
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>

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);
Output:
Error on line 8
  <currency>JPY JapaneseYen<currency>
Explanation:

In this 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.

Language(s): JavaScript XML