I am trying to assign a value to an empty XML node but it doesn't seem to be working. My XML structure is as so:
<createCustomer>
<customerAttributes>
<firstName></firstName>
<lastName></lastName>
</customerAttributes>
</createCustomer>
I am trying to assign a first name and surname in the following code:
private void createXML(Document skeleton, Map params) {
skeleton.getDocumentElement().normalize();
NodeList customerNodes = skeleton.getElementsByTagName("customerAttributes");
for(int i=0; i<customerNodes.getLength(); i++) {
NodeList children = customerNodes.item(i).getChildNodes();
for(int j=0; j<children.getLength(); j++) {
String childNode = children.item(j).getNodeName();
if(childNode.equalsIgnoreCase("firstName")){
children.item(j).setNodeValue(String.valueOf(params.get("fname")));
System.out.println(children.item(j));
}
else if (childNode.equalsIgnoreCase("lastName")){
children.item(j).setNodeValue(String.valueOf(params.get("sname")));
System.out.println(children.item(j));
}
}
}
}
}
The output of the print statements are:
firstname: null
surname: null
but I know for certain that the values in the map are correct because print statements output the expected map values. Also, if I replace the params.get("string") with a hardcoded string, I still get the output: firstname: null. The code is not throwing any exceptions. I've also tried setTextContent but this doesn't work either