Handling Parsing Errors

Now that we’re using JavaScript to load XML and XSL documents and work on them, it’s useful to know how to report parsing errors. In the preceding example, I reported errors by displaying the message “Error!” in the target <DIV> element of the HTML document, but that’s not too helpful. How can I get more information?

In the following example, I create a deliberate parsing error by changing the first <PLANET>tag in planets.xml to a <PLANETS>tag:

 <?xml version="1.0"?> <?xml-stylesheet type="text/xml" href="planets.xsl"?> <PLANETS> <PLANETS> <NAME>Mercury</NAME> <MASS UNITS="(Earth = 1)">.0553</MASS> <DAY UNITS="days">58.65</DAY> <RADIUS UNITS="miles">1516</RADIUS> <DENSITY UNITS="(Earth = 1)">.983</DENSITY> <DISTANCE UNITS="million ...

Get Inside XSLT now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.