I ma trying to reset the value of a node but for some reason the change is not reflecting. I get the tag through XPATH but it doesn't set the value I give.
reqXML is the XML file
My Code
public static String changeProductVersion(String reqXML) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document document = null;
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource source = new InputSource();
source.setCharacterStream(new StringReader(reqXML));
document = builder.parse(source);
XPath xPath = XPathFactory.newInstance().newXPath();
Element element = (Element) xPath.evaluate(NYPG3Constants.NY_PG3_RL, document, XPathConstants.NODE);
if(element != null) {
element.setTextContent("17.1.0");
System.out.println(element.getTextContent());
}
} catch (Exception ex) {
ex.printStackTrace();
}
return reqXML;
}
Thanks in advance
NYPG3Constants.NY_PG3_RLconstant? Are you just setting the value of the node in the code or do you want to save it in the file? If you want to save it, there are no instructions for it in this code.