axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Amila Suriarachchi <amilasuriarach...@gmail.com>
Subject Re: Xpath issue with Axiom/ADB
Date Fri, 23 Dec 2011 12:22:09 GMT
yes. that is the reason. Thanks Andreas.

Amila

On Thu, Dec 22, 2011 at 6:28 PM, Andreas Veithen
<andreas.veithen@gmail.com>wrote:

> On Thu, Dec 22, 2011 at 13:36, Amila Suriarachchi
> <amilasuriarachchi@gmail.com> wrote:
> > hi,
> >
> > I am getting some null pointer exceptions for some xpath queries
> executed on
> > Axiom objects. Here is a sample code to reproduce the issue.
> >
> >  OMFactory omFactory = OMAbstractFactory.getOMFactory();
> >         OMElement wrapperElement = omFactory.createOMElement(new
> > QName("http://test.com", "wrapper"));
> >
> >         PlaceOrder placeOrder = new PlaceOrder();
> >         placeOrder.setPrice(23.45);
> >         placeOrder.setQuantity(23);
> >         placeOrder.setSymbol("IBM");
> >         QName elementQName = new QName("http://test.com", "placeOrder");
> >
> >         XMLStreamReader xmlStreamReader =
> >                 BeanUtil.getPullParser(placeOrder, elementQName, null,
> true,
> > false);
> >         StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(new
> > StreamWrapper(xmlStreamReader));
> >
> >         OMElement omElement = stAXOMBuilder.getDocumentElement();
> >         wrapperElement.addChild(omElement);
> >
> >         try {
> >             AXIOMXPath axiomxPath = new
> > AXIOMXPath("//sn:wrapper/sn:placeOrder");
> >             axiomxPath.addNamespace("sn", "http://test.com");
> >
> >             OMElement resultOMElement = (OMElement)
> > axiomxPath.selectSingleNode(wrapperElement);
> >
> >             System.out.println("OMElement ==> " + resultOMElement);
> >         } catch (JaxenException e) {
> >             e.printStackTrace();
> >         }
> >
> > Here the result is null. Even I build the wrapperElement before executing
> > the xpath it won't work.
> >
> > But if I insert the following lines before xpath execution it works fine.
> >
> > String resultString = wrapperElement.toString();
> >             StAXOMBuilder resultOMBuilder = new StAXOMBuilder(new
> > ByteArrayInputStream(resultString.getBytes()));
> >             wrapperElement = resultOMBuilder.getDocumentElement();
> >
> > This means xpath and other things should be ok. And also this works fine
> for
> > the xpaths like
> >
> > //sn:placeOrder/sn:price
> >
> > what could be the reason?
>
> The fact that in the first case the root of the Axiom tree is an
> OMElement, while in the second it is an OMDocument?
>
> > thanks,
> > Amila.
> >
> > --
> > Amila Suriarachchi
> > WSO2 Inc.
> > blog: http://amilachinthaka.blogspot.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscribe@axis.apache.org
> For additional commands, e-mail: java-dev-help@axis.apache.org
>
>


-- 
Amila Suriarachchi
WSO2 Inc.
blog: http://amilachinthaka.blogspot.com/

Mime
View raw message