xpath 是否能够替换 xml 文档的值?
以下内容获取所有名称元素,但我如何替换它们?
<accounts>
<account>
<name>Johndoe1<name>
<account>
<account>
<name>Johndoe2<name>
<account>
</account>
XPathExpression fax = xpath.compile("/accounts/account/name")
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
System.out.println(nodes.item(i).getNodeValue());
}
最佳答案
Is xpath capable to replace values of a xml doc?
不,XPath 是 XML 文档的查询语言。因此,它仅从 XML 文档中提取节点和数据,但无法更改(添加、替换、删除节点)XML 文档。
当 XML 文档的处理导致创建另一个与原始文档不同的 XML 文档时,这称为 XML 转换。 XSLT 是一种专门为 XML 转换而设计的语言,是此类处理的最自然选择。
关于java - 用 xpath 替换对象列表中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13722018/