Project

Profile

Help

How to get access to the

Added by Anonymous almost 16 years ago

Legacy ID: #6389232 Legacy Poster: David Pérez (david-perez)

Hi, I've been following this instructions: http://www.saxonica.com/documentation/xpath-api/s9api-xpath.html in order to query XPath a custom tree object model through the S9API. So I've build my custom node and document wrappers. It works ok, but what I get is net.sf.saxon.tinytree.TinyElementImpl instead of my custom NodeWrapper. From a TinyElementImpl I cannot call getUnderlyingNode(), as this class doesn't implement VirtualNode. Here is a excerpt of my code (quite simple): Processor proc = new Processor(false); DocumentBuilder builder = proc.newDocumentBuilder(); DocumentWrapper wrapper = new MyCustomDocumentWrapper(myCustomDocument, null, proc.getUnderlyingConfiguration()); XdmNode doc = builder.build(wrapper); XPathSelector selector = proc.newXPathCompiler().compile("//*").load(); selector.setContextItem(doc); for (XdmItem item: selector) { System.out.println(item.getUnderlyingValue()); } Any suggestion please? Thanks in advance for any suggestion. David


Replies (5)

Please register to reply

XPath:How to access my custom nodes - Added by Anonymous almost 16 years ago

Legacy ID: #6389259 Legacy Poster: David Pérez (david-perez)

Sorry I forgot to update the title

RE: XPath:How to access my custom nodes - Added by Anonymous almost 16 years ago

Legacy ID: #6389714 Legacy Poster: David Pérez (david-perez)

I answer myself :-) The solution is quite simple, I should use static class MyNode extends XdmNode { public MyNode(NodeInfo node) { super(node); } } doc = new MyNode(wrapper); instead of: doc = builder.build(wrapper); in order to force Saxon to use my tree instead of letting it to create a new tree. I have to derive from XdmNode, as its constructor is protected.

RE: XPath:How to access my custom nodes - Added by Anonymous almost 16 years ago

Legacy ID: #6392267 Legacy Poster: David Pérez (david-perez)

I answer myself :-) The solution is quite simple, I should use static class MyNode extends XdmNode { public MyNode(NodeInfo node) { super(node); } } doc = new MyNode(wrapper); instead of: doc = builder.build(wrapper); in order to force Saxon to use my tree instead of letting it to create a new tree. I have to derive from XdmNode, as its constructor is protected.

RE: XPath:How to access my custom nodes - Added by Anonymous almost 16 years ago

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

I believe it's probably the case (though it's not well-documented and I would need to test it) that DocumentBuilder.wrap(node) can be used to create an XdmNode from any object that implements NodeInfo. I assume that this is what you mean when you talk about your "custom nodes" - your own implementation of NodeInfo. DocumentBuilder.build() will always (I think!) make a copy of the node you supply rather than wrapping it in an XdmNode. Michael Kay http://www.saxonica.com/

RE: XPath:How to access my custom nodes - Added by Anonymous almost 16 years ago

Legacy ID: #6392638 Legacy Poster: David Pérez (david-perez)

You're right Document|Builder.build() makes a copy. DocumentBuilder.wrap() I think isn't useful as I need to register an external object model. Probably my solution is simpler, and it works :-) Thanks for your suggestions.

    (1-5/5)

    Please register to reply