开发者

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 e开发者_运维知识库clipse platform.

For example,

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

the result is:

/document
/document/name
/document/size


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜