*使用JDom的XPath查询

public class Test{
  public static void main(String[] args) throws Exception{

    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build("kk.xml");
    Element root = doc.getRootElement();

    XPath xpath = XPath.newInstance("//电话[../姓名='张三'][@类型='家庭']");
     List list = xpath.selectNodes(root);

     Iterator iter = list.iterator();
     while (iter.hasNext()) {
       Element item = (Element) iter.next();
       System.err.println(item.getText());
     }


  }
posted @ 2007-05-14 15:03  健忘猪  阅读(364)  评论(0编辑  收藏  举报