Project

Profile

Help

Mapping line/column info back to dom - tumblers

Added by Rob Brown about 5 years ago

I'm working on improving validation error message handling. We're using saxon-ee and sax input to an xslt transformation. My working example is an error in the test attribute of a xsl:when element.

By catching TransformerException and using the locator I can get the line & column position of the when element and a character position within the expression itself, which is all great.

When displaying error info to the user the message is useful, but line and column are not - our users are completely insulated from xml markup and will fight to keep it that way. The UI is built around a dom structure and if I know which dom element has the error I can jump right to it and display a user-friendly expression editor.

Is there any facility in saxon that addresses this need?

If not can I request the addition of a tumbler to the net.sf.saxon.tree.AttributeLocation structure? By this I mean a space or slash separated list of integers, where each integer n locates the nth child element of the previously located element. If you always start at the document level this becomes a reliable way to map between sax and dom structures, which I also find useful for undo and other functions.

Perhaps something like this is already in saxon, but I have not been able to find it via google. Any suggestions would be greatly appreciated.


Replies (2)

RE: Mapping line/column info back to dom - tumblers - Added by Michael Kay about 5 years ago

We've done a lot of work to allow customization of the error messages arising from schema validation, because we tend to assume those messages are likely to be directed to end users rather than developers. So the Invalidity object reported to the new InvalidityHandler interface does indeed include path information that can be used to identity the erroneous element in a tree.

For syntax errors in a stylesheet we tend to assume that the error message is destined either directly for the software developer, or for an IDE that uses the information to highlight the error in the source code. I find it a little hard to see how users who don't see the XSLT source code as XML markup are ever going to be able to diagnose syntax errors in that code. However, AttributeLocation has a property getElementNode() which (if available) returns the element node in the stylesheet tree, from which you could call Navigator.getAbsolutePath(), and use the resulting path to locate the corresponding element in your original DOM.

This won't work for run-time errors because we try to avoid any reference to the source stylesheet at run-time; this supports the strategy of allowing the compiled stylesheet to be exported and distributed as a free-standing SEF file.

RE: Mapping line/column info back to dom - tumblers - Added by Michael Kay about 5 years ago

For the next major release, I have introduced a configuration option Feature.RETAIN_NODE_FOR_DIAGNOSTICS. If set, this causes the AttributeLocation to retain a reference to the element node, regardless whether the error is static or dynamic. I think this will be generally useful to people doing custom diagnostics, including our existing IDE-vendor partners.

    (1-2/2)

    Please register to reply