thandar
thandar

Reputation: 51

how to retrieve corresponding xpath

I would like to know about how to retrieve corresponding xpaths when we input an xml file in java with eclipse platform.

For example,

<document>
<name>xml file</name>
<size>12 kb</size>
</document>   

the result is:

/document
/document/name
/document/size

Upvotes: 0

Views: 3153

Answers (3)

haschibaschi
haschibaschi

Reputation: 2792

You can have this feature over firefox with the plugin firebug:

  1. Open the xml in the firefox and then go to HTML View in the firebug, if you need the XPath with Namespaces use the Additional Plugin FireXPath
  2. Right Click the xml-Element you want the XPath from and make XPath Copy
  3. In Eclipse you can evaluate the XPath with the Plugin https://github.com/stoupa91/eclipse-xpath-evaluation-plugin the XPath View which comes with the Java EE Version of eclipse

Upvotes: 3

kdgregory
kdgregory

Reputation: 39606

I'm going to assume that you (or someone else who finds this question) is looking to report a valid XPath for a specific node in a DOM. I use this quite a bit for logging, and the Practical XML library has a couple of methods to do this: DomUtil.getAbsolutePath() and DomUtil.getPath(). (disclaimer: I am the maintainer of this library).

If you're looking for something else, please try to explain yourself better.

Upvotes: 0

phunehehe
phunehehe

Reputation: 8778

Well I don't think there is a way for a computer to list all possible xpath expressions (unless you really intend to list the combinations of your expressions as well). Thus, I assume your question is "How to list the paths to all the nodes of an xml file". With this assumption I would use DOM to parse the file, then iterate to each node and print the path from the root to that note.

Upvotes: 1

Related Questions