3
XPathでノード値を設定しようとしています。私は以下を持っていますが、実際のファイルの値を変更するようには見えません。XPathを使用してノード値を設定するJava
XPathFactory factory = XPathFactory.newInstance();
XPath xPath = factory.newXPath();
xPathExpression = "//test";
xPathValue= "111";
NodeList nodes = (NodeList) xPath.evaluate(xPathExpression, new InputSource(new FileReader(fileName)), XPathConstants.NODESET);
for (int k = 0; i < nodes.getLength(); i++)
{
System.out.println(nodes.item(k).getTextContent()); // Prints original value
nodes.item(k).setTextContent(xPathValue);
System.out.println(nodes.item(k).getTextContent()); // Prints 111 after
}
ただし、そのノードのファイルの内容は変更されません。
どのようにノードの値を設定しますか?
おかげ