码迷,mamicode.com
首页 > 其他好文 > 详细

A powerful tool to parse xml -- Xpath!

时间:2017-07-13 20:38:15      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:from   could   cts   pow   single   java   pos   power   express   

The Xpath‘s javadoc could be got from the Dom4j‘s javadoc.

There are some simple regulation you must follow:

  1.When you want to use specific single node:

    /AAA

    /AAA/CCC

  2.When you want to use all the nodes which have the same name:

    //BBB

    //DDD/CCC

  3. * represent all the nodes in the specific path:

    /AAA/*

    //*     --------->  all the nodes

  4.The expression which has the square brackets could further specify the node. The number in the bracket gives the position you select/

    /AAA[1]

    //BBB/CCC[last()]

  5.The attribute will be got by the @

    //@id

    /AAA[@id]

 

But after knowing the regulation , where should we put it?

  //Get the document object

  SAXReader reader = new SAXReader();

  Document document = reader.read("");

  //get the data of node via document‘s selecNodes() or selectSingleNode()

  List<Node> nodes = document.selectNodes(" you can set your regulation here!!");

  Node node = document.selectSingleNode(" you can set your regulation here!!");

  

A powerful tool to parse xml -- Xpath!

标签:from   could   cts   pow   single   java   pos   power   express   

原文地址:http://www.cnblogs.com/ppcoder/p/7162047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!