- SAXReader saxReader = new SAXReader();
- try {
- Document document = saxReader.read(new File(filename));
- Element root = document.getRootElement();
- HashMap xmlMap = new HashMap();
- xmlMap.put("plugins","http://www.**.com/yanfa/appmonschema"); //http://www.**.com/yanfa/appmonschema为命名空间
- XPath x = document.createXPath("//plugins:AppMonConfig/plugins:outputStrategy/plugins:monStrategy/plugins:item/plugins:targetId"); //读取targetId节点
- x.setNamespaceURIs(xmlMap);
- Element valueElement = (Element)x.selectSingleNode(document);
- System.out.println(valueElement.getText()); //输出该节点内容
- }catch(Exception e){
- }
用dom4j解析带命名空间的xml文件
最新推荐文章于 2022-10-21 17:37:45 发布