January 23, 2002 - Parsing Error Pinpointing

Yehuda Shiran January 23, 2002
Parsing Error Pinpointing
Tips: January 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Internet Explorer's XML parser provides a lot of information about parsing errors. You can print to the user the location of the error within the XML file, the line number within the XML file, the character position in the line, the reason for the error, the text of the XML line where the error has been detected, and the URL of the XML file. This load() function prints all these attributes for an XML file which includes an error:

function load() {
  var xmldoc;
  xmldoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
  xmldoc.async = false;
  xmldoc.load("mydvdwitherror.xml");
  if (xmldoc.parseError.errorCode != 0) {
    alert("errorCode: " + xmldoc.parseError.errorCode + "\n" +
          "filepos: " + xmldoc.parseError.filepos + "\n" +
          "line: " + xmldoc.parseError.line + "\n" +
          "linepos: " + xmldoc.parseError.linepos + "\n" +
          "reason: " + xmldoc.parseError.reason + "\n" +
          "srcText: " + xmldoc.parseError.srcText + "\n" +
          "url: " + xmldoc.parseError.url);
    } else {
        alert(xmldoc.documentElement.xml);
      }
}
We took a valid XML file and modified the </DATA> field to <DATA>. We put the XML file in mydvdwitherror.xml. Try loading this file. You should get an alert box with all the error information described above.