Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Assign value to an XML Node
    primarykey
    data
    text
    <p>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:</p> <pre><code>&lt;createCustomer&gt; &lt;customerAttributes&gt; &lt;firstName&gt;&lt;/firstName&gt; &lt;lastName&gt;&lt;/lastName&gt; &lt;/customerAttributes&gt; &lt;/createCustomer&gt; </code></pre> <p>I am trying to assign a first name and surname in the following code:</p> <pre><code>private void createXML(Document skeleton, Map params) { skeleton.getDocumentElement().normalize(); NodeList customerNodes = skeleton.getElementsByTagName("customerAttributes"); for(int i=0; i&lt;customerNodes.getLength(); i++) { NodeList children = customerNodes.item(i).getChildNodes(); for(int j=0; j&lt;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)); } } } } } </code></pre> <p>The output of the print statements are:</p> <p><code>firstname: null</code> <code>surname: null</code></p> <p>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 <code>params.get("string")</code> with a hardcoded string, I still get the output: <code>firstname: null</code>. The code is not throwing any exceptions. I've also tried <code>setTextContent</code> but this doesn't work either</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload