| Author |
Using XPath - Java returns the NodeList in document order - how can I fix it ?
|
david ron
Greenhorn
Joined: May 05, 2012
Posts: 7
|
|
Hello ,
I need to fix a known example is XPath 1.0 - the reversed axis .
Given the following XML file as an example for what is written afterwards :
I need to fix a known problem in XPath 1.0 , which known as the Reverse Axis . A little example might clarify :
When I enter the following query :
Output would be :
However what I want is when my XPath uses the preceding-sibling axis ,I want to return the nodes in a reverse order , i.e. :
Apparently, Java returns the NodeList in document order.
As you can see ,Java returns the nodes by the order of the nodes in the XML file , but what I need is , when XPath
uses the preceding-sibling axis ,then return the nodes in a reverse order .
This is not the one and only command where this kind of "behavior" is happening (returning mixed nodes) .
My objective is to fix this , I've tried to change XPath's evaluate , but it's still doesn't work .
Can anyone give some directions / hints how to do this ?
I've started with rewriting the evaluate method , but nothing so far .
I'm not allowed to use XPath 2.0.
I used the following code to produce the example above :
Regards
David
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12266
|
|
Why not iterate through the NodeList from high to low?
Bill
|
Java Resources at www.wbrogden.com
|
 |
david ron
Greenhorn
Joined: May 05, 2012
Posts: 7
|
|
William Brogden wrote:Why not iterate through the NodeList from high to low?
Bill
Try it for your self ,it still would be in incorrect order . Furthermore ,as I said ,I need to make to code work with every query , meaning
that there are queries where we'd need no reverse - hence there is no need to iterate through the NodeList from high to low - if you do that , the answer would be incorrect !!
I'd appreciate any suggestions . thanks
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12266
|
|
If you want absolute control then work with the DOM directly using the standard library instead of XPath.
Bill
|
 |
 |
|
|
subject: Using XPath - Java returns the NodeList in document order - how can I fix it ?
|
|
|