Project

Profile

Help

ClassCastException TinyElementImpl

Added by Anonymous about 17 years ago

Legacy ID: #4492170 Legacy Poster: kendall shaw (queshaw)

I'm using net.sf.saxon.xpath.XPathEvaluator.evaluate(String, Node, XPathConstants.NODE) with saxon b 8.9.04 and casting the result to a Node, which gets me a ClassCastException. Is there a way to get a DOM node from the result?


Replies (3)

Please register to reply

RE: ClassCastException TinyElementImpl - Added by Anonymous about 17 years ago

Legacy ID: #4492973 Legacy Poster: kendall shaw (queshaw)

I should probably mention that I have been getting a result that I can cast to Node, but when the expression contains a doc() function, I get the ClassCastException. Can I get a Node from this result some how?

RE: ClassCastException TinyElementImpl - Added by Anonymous about 17 years ago

Legacy ID: #4493092 Legacy Poster: kendall shaw (queshaw)

This looks like a solution to the problem I'm having currently: try { o = xpath.evaluate(...) return (Node) o; } catch (ClassCastException ex) { if (o instanceof NodeInfo) { return (Node) NodeOverNodeInfo.wrap(o); } throw ex } The javadoc says that ElementOverNodeInfo gets a read-only Node. I don't think I need anything but a read-only copy of the DOM, so that seems okay.

RE: ClassCastException TinyElementImpl - Added by Anonymous about 17 years ago

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

The JAXP specification is pretty inadequate in this area. It supports XPath in a model-independent way, that is, it's not committed to the DOM, so my interpretation of the return type XPathConstants.NODE is "a node in whatever object model it happens to be in". If you want a call on doc() to return DOM nodes rather than Saxon nodes, the way to do it is to supply a URIResolver for the doc() function that builds the DOM and returns a DOMSource that wraps it. Unfortunately as soon as you do this you are going outside the JAXP interface, which means that your code only works with Saxon, and if you're going to write Saxon-specific code then you're probably better off using the net.sf.saxon.sxpath package instead of JAXP. Michael Kay

    (1-3/3)

    Please register to reply