StandaloneContext in saxonA-8.9.0.4
Added by Anonymous about 17 years ago
Legacy ID: #4530862 Legacy Poster: Jocelyn Raymond (jraymond67)
Hi, Hopefully someone can help me. I was looking into how I can set a namespace for the XPathEvaluator/XPathExpression object. Some old code suggested something like: StandaloneContext context = new StandaloneContext(); context.declareNamespace("d", "default-namespace"); etc... However, when I look at the documented API for 8.9.0.4, StandaloneContext cannot be found. Was StandaloneContext removed? If not, where can I find it? If yes, how do we "declare" a namespace when I want to apply an XPath on a node context in a specific namespace? I did look at XPathExample.java but not sure if I understand it completely. The example does not use namespace (except the "saxon" one). Will I have to implement NamespaceContext interface in order to be able to add my namespace? If yes, would it be simply the getNamespaceURI(String prefix) method? Thanks in advance for your help, Jocelyn Raymond
Replies (2)
RE: StandaloneContext in saxonA-8.9.0.4 - Added by Anonymous about 17 years ago
Legacy ID: #4531362 Legacy Poster: Michael Kay (mhkay)
There are two versions of XPathEvaluator/XPathExpression - those in package net.sf.saxon.xpath (which follow the JAXP model) and those in net.sf.saxon.sxpath (which are specific to Saxon, and better adapted to XPath 2.0). I'm afraid you don't make it clear which you are using. The JAXP mechanism is XPathEvaluator.setNamespaceContext(), to which you must supply a NamespaceContext object; Saxon will only call one method on this object, the getNamespaceURI(prefix) method. Unfortunately the JAXP NamespaceContext interface provides no way to determine all the in-scope namespace bindings, which is functionality that is needed by an XPath 2.0 processor, so when you use this method certain functionality is not available. In the sxpath package, Saxon's XPathEvaluator provides a very similar method XPathEvaluator.setNamespaceResolver; the NamespaceResolver has two methods getURIForPrefix() and iteratePrefixes() which you should implement. Both versions of XPathEvaluator contain a StaticContext object. For the sxpath version this will by default be an instance of the class IndependentContext. This allows you to declare a namespace by using ((IndependentContext)xpathEvaluator.getStaticContext()).declareNamespace(prefix, uri); The old StandaloneContext class was used in a number of places, and was split up into a number of separate implementations of the StaticContext interface for use in different circumstances. Michael Kay Saxonica Limited
RE: StandaloneContext in saxonA-8.9.0.4 - Added by Anonymous about 17 years ago
Legacy ID: #4531375 Legacy Poster: Jocelyn Raymond (jraymond67)
Hi Michael, Thanks for clarifying this. I would like to use the XPathEvaluator from the sxpath package (specific to Saxon). However, it does look a little more complex to setup. So I guess, I will pull up my sleeves over the weekend and figure this one out. Thanks again for all the details, Jocelyn Raymond
Please register to reply