Dom4j使用xpath查询xml文

Dom4j使用xpath查询带有命名空间的xml文件

方式1

忽略命名空间

java 复制代码
DocumentFactory factory = DocumentFactory.getInstance();
SAXReader reader = new SAXReader(factory);
Document document = reader.read(xmlFilePath);
Element rootElement = document.getRootElement();
Node node = document.selectSingleNode("//*[local-name()='NOC']/*[local-name()='Section' and @fileRef='nncFireGround.xml']/*[local-name()='NavigationItem' and @idRef='CHDEDCHHA6']");

方式2

定义前缀

java 复制代码
Map<String,String> map = new HashMap<>();
map.put("s","http://www.boeing.com/FTID-ML");
factory.setXPathNamespaceURIs(map);

XPath xPath = factory.createXPath("/s:NOC/s:Section[@fileRef='nncFireGround.xml']/s:NavigationItem[@idRef='CHDEDCHHA6']");
Node node = xPath.selectSingleNode(document);
相关推荐
spencer_tseng3 天前
[j2cache ehcache.xml]/tmp/.ehcache-diskstore.lock (Permission denied)
xml·linux·python·ehcache·[j2cache
DevOpenClub4 天前
PDF 多格式解析如何避免混用输出:TEXT、HTML、XML 与 TAG 数据契约
xml·前端·数据库·pdf·html
Java小白笔记4 天前
MyBatis XML Mapper 标签与 CRUD 原理实战
xml·数据库·mybatis
风萧萧19995 天前
JAVA :JSONObject转换为XML
xml·java·python
马优晨7 天前
pom.xml 中 jquery webjars 依赖解释
xml·前端·jquery·jquery webjars·webjars依赖
楚识科技8 天前
定制 OCR 服务:非标证件与表格的 XML 字段映射实践
xml·ocr
光泽雨9 天前
JSON /XML转换
xml·json
我命由我1234510 天前
UI 设计 7 种排列方式
xml·学习·ui·html·产品运营·产品经理·学习方法
ly768915 天前
XML 从入门到实践:语法、命名空间、XPath、XSD 与 Java 安全解析
xml·java·python