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

Reply via email to