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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint