Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Get full path to node (Java XPath)?

807580Aug 13 2009 — edited Aug 13 2009
I am using javax.xml.xpath.*; to navigate a xml file and retrieve elements. But now I need to get the full path based on the name of an element. Given the below file the element <price> has the path:

/inventory/book/price

Is there someway to use javax.xml.xpath to return this full path when only specifying the argument 'price' ?

<inventory>
<book year="2000">
<title>Snow Crash</title>
<author>Neal Stephenson</author>
<publisher>Spectra</publisher>
<isbn>0553380958</isbn>
<price>14.95</price>
</book>

<book year="2005">
<title>Burning Tower</title>
<author>Larry Niven</author>
<author>Jerry Pournelle</author>
<publisher>Pocket</publisher>
<isbn>0743416910</isbn>
<price>5.99</price>
</book>

<book year="1995">
<title>Zodiac</title>
<author>Neal Stephenson</author>
<publisher>Spectra</publisher>
<isbn>0553573862</isbn>
<price>7.50</price>
</book>

<!-- more books... -->

</inventory>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 10 2009
Added on Aug 13 2009
4 comments
1,868 views