jdom xpath 带 namespace 搜索

SAXBuilder builder=new SAXBuilder();
  
    Document doc1=builder.build(this.getClass().getResource("xmlfiles/test.xml"));  

 

   //搜所有节点名为name 且其属性use==ABC的所有节点
    XPath xpath=XPath.newInstance("//v3:name[@use='ABC']");
  xpath.addNamespace("v3", "urn:hl7-org:v3");
  List list=xpath.selectNodes(doc1);
  Iterator iter = list.iterator();
  while (iter.hasNext()) {
  
  Element item = (Element) iter.next();
   item.getChild("family", item.getNamespace()).setText(ename.substring(0,idx));
  item.getChild("given", item.getNamespace()).setText(ename.substring(idx));
   System.err.println(item.getChildText("family", item.getNamespace()));
  
//   List l=item.getChildren();
//   Iterator iter1 = l.iterator();
//   while(iter1.hasNext()){
//    Element item1 = (Element) iter1.next();
//    System.out.println(item1.getText());
//   }
   }

你可能感兴趣的:(xml)