I checked the XPath specs and this is actually the expected behavior.
The reason is that //sn:wrapper/sn:placeOrder is an abbreviation for
/descendant-or-self::node()/child::sn:wrapper/child::sn:placeOrder.
Therefore the node set is empty if sn:wrapper is the root node.
However the following expression should work in both cases:
/descendant-or-self::sn:wrapper/sn:placeOrder/.

Andreas

On Fri, Dec 23, 2011 at 13:22, Amila Suriarachchi
<amilasuriarach...@gmail.com> wrote:
> yes. that is the reason. Thanks Andreas.
>
> Amila
>
> On Thu, Dec 22, 2011 at 6:28 PM, Andreas Veithen <andreas.veit...@gmail.com>
> wrote:
>>
>> On Thu, Dec 22, 2011 at 13:36, Amila Suriarachchi
>> <amilasuriarach...@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-unsubscr...@axis.apache.org
>> For additional commands, e-mail: java-dev-h...@axis.apache.org
>>
>
>
>
> --
> Amila Suriarachchi
> WSO2 Inc.
> blog: http://amilachinthaka.blogspot.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscr...@axis.apache.org
For additional commands, e-mail: java-dev-h...@axis.apache.org

Reply via email to