Xpath 处理带有命名空间的xml



























SAXReader saxReader = new SAXReader();
Document document;
try {
document = saxReader.read(new File(path + processKey));
Map nameSpaceMap = new HashMap();
nameSpaceMap.put("jbpm", "http://jbpm.org/4.4/jpdl");
//设置命名空间
saxReader.getDocumentFactory().setXPathNamespaceURIs(nameSpaceMap);
//使用xpath找节点的时候前面加 jbpm: 就可以找到。
Element eleTask = (Element) document.selectSingleNode("/process/jbpm:decision[@name='" + nodeName + "']");
OutputFormat format = new OutputFormat("", false, "utf-8"); // 设置输出格式为空两格,换行,编码为utf-8
XMLWriter writer = new XMLWriter(new FileOutputStream(path +processKey), format); // 创建输出对象
writer.write(document);
writer.close();
} catch (DocumentException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

你可能感兴趣的:(Xpath 处理带有命名空间的xml)