开发者

Is there jQuery like selectors for Java XML parsing?

When I want to find elements from XML in with jQuery, i can just use CSS selectors. Is there any similar selector system for XML 开发者_如何学Goparsing in Java?


The query syntax for XML is called XPath.


I am currently creating a sort of "jQuery port to Java". It is called jOOX and will provide most of jQuery's DOM navigation and manipulation methods. In addition to a simple selector expression language, standard XPath and XML transformation is supported, based on the standard Java DOM API

https://github.com/jOOQ/jOOX

Some sample code:

// Find the order at index for and add an element "paid"
$(document).find("orders").children().eq(4)
           .append("<paid>true</paid>");

// Find those orders that are paid and flag them as "settled"
$(document).find("orders").children().find("paid")
           .after("<settled>true</settled>");


You can use either E4X or XPath to query your XML file. I would recommend using the new E4X technology as it's more easy to use than XPath.

jQuery only offers standard hierarchical functions to parse XML files (see here) as it's not his purpose to do otherwise.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜