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);
相关推荐
gAlAxy...37 分钟前
MyBatis 核心配置文件 SqlMapConfig.xml 全解析
xml·mybatis
编程修仙1 天前
第十一篇 Spring事务
xml·java·数据库·spring
金士顿1 天前
Ethercat耦合器添加的IO导出xml 初始化IO参数
android·xml·java
烤麻辣烫2 天前
黑马程序员苍穹外卖后端概览
xml·java·数据库·spring·intellij-idea
暗碳2 天前
安卓abx二进制xml文件转换普通xml文件
android·xml
jinxinyuuuus2 天前
文件格式转换工具:XLSX的XML流式解析、数据类型推断与CSV编码规范
xml
czlczl200209252 天前
从抛出异常到返回 JSON/XML:SpringBoot 异常处理全链路解析
xml·spring boot·json
jiayong232 天前
MyBatis XML Mapper 特殊字符处理方案
xml·mybatis
e***19353 天前
【mybatis】基本操作:详解Spring通过注解和XML的方式来操作mybatis
xml·spring·mybatis
编程修仙3 天前
第七篇 java的注解以及使用反射实现自定义注解功能
xml·java·开发语言·spring