阅读背景:

如何在Java中使用xpath来查找xml中的节点值或属性,并将其替换为另一个值?

来源:互联网 

Here is my Code so far:

这是我目前的代码:

// locate the node(s)
XPath xpath = XPathFactory.newInstance().newXPath();
NodeList nodes = (NodeList)xpath.evaluate("//root[text()='input[1]']", doc, XPathConstants.NODESET);

// make the change
for (int idx = 0; idx < nodes.getLength(); idx++) {
    nodes.item(idx).setTextContent(input[3]);
}

// save the result
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.transform(new DOMSource(doc), new StreamResult(new File(outputFile)));
// locate



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: