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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business