You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Paul Fremantle <pz...@gmail.com> on 2005/11/21 10:09:48 UTC

Re: [Axis2] Navigation of XML Doc via AxiomXpath.

Saminda

I think the problem is that it is searching from the current node. So your
element is t:text. There is no child in that for it to search.
But maybe this should be fixed. I'm no Jaxen expert!

Paul

On 11/21/05, Saminda Abeyruwan <sa...@opensource.lk> wrote:
>
> Hi Devs,
>
> I'm using AxiomXpaht to navigate XML. Let's say, i have to navigate a
> SOAP env and find a match for "//t:text". So simply i can comeup with
> the following code,
>
> SOAPEnvelope dumEnv =
> OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
> OMFactory fac = OMAbstractFactory.getOMFactory();
> OMElement ele = fac.createOMElement("text","urn:text-body","t");
> dumEnv.getBody().addChild(ele);
> SimpleNamespaceContext nsc = new SimpleNamespaceContext();
> XPath xp = null;
> try {
> xp = new AXIOMXPath("//t:text");
> nsc.addNamespace("t", "urn:text-body");
> xp.setNamespaceContext(nsc);
>
> System.out.println(xp.selectSingleNode(dumEnv));
> System.out.println(xp.booleanValueOf(dumEnv));
>
> } catch (JaxenException e) {
> e.printStackTrace();
> }
>
> Which will throw following exception,
> ==================================================================
> java.lang.NullPointerException
> at
> org.apache.axis2.om.xpath.DocumentNavigator.getDocumentNode(
> DocumentNavigator.java:589)
> at
> org.apache.axis2.om.xpath.DocumentNavigator.getDocumentNode(
> DocumentNavigator.java:589)
> at
> org.jaxen.expr.DefaultAbsoluteLocationPath.evaluate(
> DefaultAbsoluteLocationPath.java:106)
> at org.jaxen.expr.DefaultXPathExpr.asList(DefaultXPathExpr.java:108)
> at org.jaxen.BaseXPath.selectNodesForContext(BaseXPath.java:705)
> ===================================================================
>
> Now if i modified the code to wrap the SOAP env in *OMDocument* adding
> following two lines to the above code,
>
> OMDocument doc = fac.createOMDocument();
> doc.addChild(dumEnv);
>
> Jaxen will show the intended behavior, simply works fine.
>
> So, it seems that even for a simple task when we using AxiomXpath, we
> have to wrap the OMElement with OMDocument. Is this behavior in
> *DocumentNavigator* correct ?. Why do we have to wrap OMElement with
> OMDocument?
>
> Thank you
>
> Saminda
>
>