用dom4j解析带命名空间的xml文件

  1. SAXReadersaxReader=newSAXReader();
  2. try{
  3. Documentdocument=saxReader.read(newFile(filename));
  4. Elementroot=document.getRootElement();
  5. HashMapxmlMap=newHashMap();
  6. xmlMap.put("plugins","http://www.**.com/yanfa/appmonschema");//http://www.**.com/yanfa/appmonschema为命名空间
  7. XPathx=document.createXPath("//plugins:AppMonConfig/plugins:outputStrategy/plugins:monStrategy/plugins:item/plugins:targetId");//读取targetId节点
  8. x.setNamespaceURIs(xmlMap);
  9. ElementvalueElement=(Element)x.selectSingleNode(document);
  10. System.out.println(valueElement.getText());//输出该节点内容
  11. }catch(Exceptione){
  12. }

你可能感兴趣的:(用dom4j解析带命名空间的xml文件)