Bug #1587


How can I handle errors of the type 'xml input file does not exist?

Added by Jeff Holt almost 12 years ago. Updated about 11 years ago.

Start date:
Due date:
% Done:


Estimated time:


I downloaded Saxon-CE version 1.0 and after getting some code to work, I have attempted to implement one of the solutions for passing parameters from the URL to the HTML file to the XSLT transform object. That seems to work but the Javascript API method for handling errors does not handle the error that happens when the processor executes the asynchronous GET for the xml input file, upon with the transformation takes place.

Below are the scripts that make up the bulk of the booting in the HTML file. As you can see from the code, I'm expecting Saxon.requestXML(xmlfile) to return null if the file does not exist. But it apparently always returns some object. Likewise, I'm expecting proc.updateHTMLDocument(xml) to raise an exception but it doesn't either. I believe that the GET on the xml file being done asynchronously is the cause of the problem with the error not being raised. So, how can such an exception be trapped? How many other exceptions might not be catchable?

@<script type="text/javascript" language="javascript" src="../SaxonceDebug/Saxonce.nocache.js"></script>

<script type="text/javascript" language="javascript"> var errors = new Array(); function errorHandler(saxonError) { errors.push(saxonError.message + " " + saxonError.level + " " + saxonError.time); } function getURLParams() { var params = {}; var hrefstr = window.location.href; hrefstr.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { params[key] = value; }); return params; } function onSaxonLoad() { var params = getURLParams(); var xmlfile = params['xmlfile']; if (xmlfile == null) { document.getElementById('status').innerHTML = "

The 'xmlfile' parameter is not present in the URL.

"; return; } Saxon.setErrorHandler(errorHandler); Saxon.setLogLevel("FINE"); var xml = Saxon.requestXML(xmlfile); try { xml = Saxon.requestXML(xmlfile); if (xml == null) { document.getElementById('status').innerHTML = "

The 'xmlfile' parameter specifies a filename, '" + $xmlfile + "', that cannot be read."; return; } } catch(e) { window.alert('requestXML: ' + e.message); } var xsl = Saxon.requestXML('prof.xsl'); var proc = Saxon.newXSLT20Processor(xsl); proc.setParameter(null, 'xmlfile', xmlfile); document.getElementById('status').innerHTML = "

Page loading...

"; try { proc.updateHTMLDocument(xml); } catch(e) { window.alert(e.message); } if (errors.length > 0) { window.alert(errors.toString()); } } </script>@

Please register to edit this issue

Also available in: Atom PDF