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);
相关推荐
鹏晨互联14 小时前
【Compose vs XML:边框内外间距的实现对比】
android·xml
鹏晨互联2 天前
Jetpack Compose vs XML:fillMaxSize、fillMaxHeight、fillMaxWidth 全面对比
android·xml
如果'\'真能转义说3 天前
OOXML 文档格式剖析:哈希、ZIP结构与识别
xml·算法·c#·哈希算法
ZC跨境爬虫4 天前
跟着 MDN 学 HTML day_34:(深入XML 中的 CDATASection 接口)
xml·前端·html·html5·媒体
hmywillstronger4 天前
【Python】从SAP2000 XML截面库提取数据到Excel
xml·python·excel
Boop_wu4 天前
[Mybatis] XML 方式实现 MP 自定义 SQL + 条件构造器
xml·sql·mybatis
曹牧4 天前
Oracle:将包含属性(Attributes)的 XML 数据解析为表格数据
xml·数据库·oracle
阿维的博客日记5 天前
传统 Spring XML 配置 vs Spring Boot Starter 对比文档
xml·spring boot·spring
Cx330❀8 天前
Qt 入门指南:从零搭建开发环境到第一个图形界面程序
xml·大数据·开发语言·网络·c++·人工智能·qt