views:

77

answers:

3

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
+1  A: 

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.

phunehehe
A: 

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.

kdgregory
A: 

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 http://www.bastian-bergerhoff.com/eclipse/features/web/XPathDeveloper/toc.html or the XPath View which comes with the JEE Version of eclipse
haschibaschi