>Cramps on SAX2 and Xalan

>I checked in some code over the last few days for the XSL Tooling project that leverages the Xalan XSLT compiler for compilation syntax checking of XSLT 1.0 documents. This was a more painful process then it should have been.

Xalan Annoyances.

Xalan 2 has the annoying habit of treating any error it encounters before transformation begins as a Fatal Error. While I can see why they would do this if you were just trying to run a straight transformation, but it’s really annoying when you are just trying to make sure that your syntax is correct and variables are correctly defined. Out of the box customization is needed to handle this, even though Xalan supports the ability to have an ErrorListener class to handle errors.

To solve this, I ended up creating a customized version of the process that creates the compiled Templates that are used before transformation begin. No this isn’t the XSLTC compilation that goes to byte code, but the actual creation of the javax Templates instatiations. Their are really only about 3 places where some try/catches need to be placed to catch the errors that were being tossed. This allows the ErrorListener to catch and report all the errors that it can catch before runtime. However, there are still several errors that can only be caught during runtime, but it’s better than getting one error reported, fixing it, getting another error reported, fixing it, etc.

SAX2 Cramps.

SAX2 has a Locator implementation that is supposed to give the line number and column number of the current location. Unfortunately from a XML Editor standpoint, the implementation doesn’t give the beginning column number but the ending column number instead. So, it doesn’t give very accurate positions of which particular element had the issue. The SAXException can get a locator but again it only returns the line and ending column number. You can get around the issue but it takes some locator magic to do it. Basically in the startElement and endElement methods in your Handler, you need to call the Locator to get what it thinks are the positions at that point in time… and then do your own tracking. This is very similar to how WTP handles Xerces and XML Validation. It would have been nicer to have the SAXException automatically have this information.

The current compiler may not make it into 0.5M6, but it will probably be in place for 0.5M7. I need to talk to my fellow XSL Tooling committers to figure out what we are going to do. Community feed back either here or via bugzilla would be appreciated.

This entry was posted in eclipse, xml, xsl. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s