*使用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());
}
}
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());
}
}