spacer
Yehuda Shiran February 20, 2002
Printing A Parsing Error
Tips: February 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Going Native With Chrome
Mozilla Fixes Firefox Flaws as 3.5 Release Nears
Microsoft and Novell Still Bosom Buddies

When loading XML files, you must keep error handling in place. Otherwise, debugging the XML, DTD, and XSL files is going to be very time consuming. The following script reads mydvd7.xml, prints a relevant error message if the parsing was not successful, and prints the DOM tree otherwise:

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
var namedNodeMap;
xmlDoc.async = false;
xmlDoc.load("mydvd7.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);
  }

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 >
XML and PHP Simplified · Creating a ASP.NET Contact Form · Data Filtering with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Intel to Host Live Nehalem Q&A · 12 Tips to Troubleshoot Network File-Sharing · 10 Tips for Selling on Kijiji