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

Yehuda Shiran, Ph.D.
Doc JavaScript

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

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

webref The latest from WebReference.com Browse >
Creating a Banking Application Deposit Script · Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Best Buy to Market Phone Power VoIP Service · Industry Insiders: Ted Morgan, CEO, Skyhook Wireless · Chip Market Recovering From '08 Collapse