Project

Profile

Help

DocumentFragment & XPath problem

Added by Anonymous over 18 years ago

Legacy ID: #3461642 Legacy Poster: blstein (blstein)

I experienced a problem while upgrading from Saxon8.4 to 8.6.1 in my XPath related code. Running a XPath query on a DocumentFragment results in an IllegalArgumentException: java.lang.IllegalArgumentException: Unsupported node type in DOM! 11 instance [#document-fragment: null] at net.sf.saxon.dom.NodeWrapper.makeWrapper(NodeWrapper.java:107) at net.sf.saxon.dom.NodeWrapper.makeWrapper(NodeWrapper.java:63) at net.sf.saxon.dom.DocumentWrapper.wrap(DocumentWrapper.java:57) at net.sf.saxon.dom.DOMObjectModel.wrapNode(DOMObjectModel.java:306) at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:210) at net.sf.saxon.xpath.XPathEvaluator.evaluate(XPathEvaluator.java:327) at XPathTest.testXPath(XPathTest.java:55) I've written a small unit test and ran it against some recent Saxon releases (8.6.1, 8.6, 8.5.1, 8.5 and 8.4) and the query only succeeds on Saxon8.4. The Sun java API specifies (http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/xpath/XPath.html) that DocumentFragment is treated like a Document node, so I assume my query should work. Am I doing anything wrong, or could there be a problem in Saxon releases after version 8.4? The unit test can be found at http://first.sipri.org/bram/XPathTest.java and requires JUnit to run. Thanks, Bram Stein


Replies (7)

Please register to reply

RE: DocumentFragment & XPath problem - Added by Anonymous over 18 years ago

Legacy ID: #3461711 Legacy Poster: Michael Kay (mhkay)

Thanks for reporting it. I'll look into it, though it will have to wait a few days. I'm surprised it ever worked: it can only have worked by chance, since the code that's rejecting document fragments has not changed. Michael Kay

RE: DocumentFragment & XPath problem - Added by Anonymous over 18 years ago

Legacy ID: #3467292 Legacy Poster: weso (soergel)

Hi, I have the same problem with Node-Type ENTITY_REFERENCE_NODE. java.lang.IllegalArgumentException: Unsupported node type in DOM! 5 instance [pab_TEST_A_BLK: null] at net.sf.saxon.dom.NodeWrapper.makeWrapper(NodeWrapper.java:107) I have updated from version 6.5 to version 8.6.1 Will be this Node-Type supported in the DOMWrapper in any future version? Thanks Werner

RE: DocumentFragment & XPath problem - Added by Anonymous over 18 years ago

Legacy ID: #3467541 Legacy Poster: Michael Kay (mhkay)

I have no plans to add support for a DOM that contains EntityReference nodes. It's a pretty complex job mapping this correctly to the XPath data model, especially handling issues like node identity correctly. You'd be better off copying the DOM to a Saxon tree. Michael Kay

RE: DocumentFragment & XPath problem - Added by Anonymous over 18 years ago

Legacy ID: #3467581 Legacy Poster: weso (soergel)

How can I copy a DOM to a Saxon tree? Please can you give me a starting point in your API. Thanks Werner

RE: DocumentFragment & XPath problem - Added by Anonymous over 18 years ago

Legacy ID: #3467582 Legacy Poster: blstein (blstein)

Thanks, a solution would be much appreciated. I spent some time going through and comparing the 8.4 and 8.51 source code after I found the problem. I was also quite surprised that the code that's rejecting the DocumentFragments was the same in both versions. Anyway, as there are multiple solutions for working around the problem, there's no time pressure. Bram Stein

RE: DocumentFragment & XPath problem - Added by Anonymous over 18 years ago

Legacy ID: #3469209 Legacy Poster: Michael Kay (mhkay)

The simplest way to do this is probably with an identity transform, supplying a DOMSource as the source and a Saxon Builder as the result: TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); TinyBuilder b = new net.sf.saxon.event.TinyBuilder(); t.transform(new DOMSource(domDoc), b) net.sf.saxon.om.NodeInfo saxonDoc = b.getCurrentRoot(); I'm afraid I'm rather conscious that there's an awful lot of API documentation to wade through to find the bit that you need.... Michael Kay

RE: DocumentFragment & XPath problem - Added by Anonymous over 18 years ago

Legacy ID: #3471131 Legacy Poster: weso (soergel)

Thank you for the assistance. The Saxon is a great XSLT processor.

    (1-7/7)

    Please register to reply