开发者

Express XPath as an expression tree

If I have an XPath query like

No开发者_开发技巧deA/NodeB[@WIDTH and not(@WIDTH="20")] | NodeC[@WIDTH and not(@WIDTH="20")]/NodeD

Is there any API available to visualize this XPath query as a stack of atomic expressions, something like (following is generic)

  1. Get results of NodeA, call it "first set"
  2. Get results of NodeB from "first set"
  3. Filter where [@WIDTH and not(@WIDTH="20")]
  4. Filter NodeD, call this "node d for B"
  5. Get results of NodeC from "first set"
  6. Filter where [@WIDTH and not(@WIDTH="20")]
  7. Filter NodeD, call this "node d for C"
  8. Combine "node d for B" and "node d for C"

I am trying to see if we can convert the XPath expression into custom expression which is close to english and vice versa.

If no API is available, what would be the best approach? Thanks in advance.


You can use any open source XPath parser and customize it for your needs, but this could be quite challenging.

XQuery has a XML-based representation (XQueryX) and this covers XPath 2.0 completely. However people have to write in this XML representation, not the reverse. I am not aware of a translator between XQuery and XQueryX. If such existed, it would come close to serving your needs.

Update: There is such translating tool: the W3C XPath/XQuery Applets. Especially see the Grammar Test Page for XPath 2.0.

Here is how the tool works:

alt text http://www.freeimagehosting.net/uploads/c85e730293.png

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜