title: Changing node name of xml-node with Java
body: <p>I have following scenario: I have a XML-Document, e.g. like this</p>
  
  <pre><code>&lt;someRootElement&gt;
  &lt;tag1&gt;
      &lt;tag2 
          someKey=someValue
          someKey2=someValue2
      /&gt;
      &lt;tag3/&gt;
      &lt;tag4
          newKey=newValue
          newKey2=newValue2
      /&gt;
  &lt;/tag1&gt;
  &lt;/someRootElement&gt;
  </code></pre>
  
  <p>Now I want the parent <strong>tag1</strong> to be called <strong>reallyCoolTag</strong> without losing the childnodes.
  I tried the following, but it unfortunately doesn't work as I wish it would (but I do know why, b/c it is missing something, I guess):</p>
  
  <pre><code>// the new element:
  Element neu = doc.createElement( newValue );
  // append it to the root:
  root.appendChild( neu );
  // get all the child nodes:
  NamedNodeMap nnm = nodes.item(i).getAttributes();
  for( int dg = 0; dg &lt; nnm.getLength(); dg++ ){
      neu.setAttribute(  nnm.item( dg ).getNodeName(),
      nnm.item( dg ).getNodeValue() );
  }
  //---------------------------------------------------------
  // HERE I GUESS I AM MISSING THE PART WHERE THE CHILD NODES
  // ARE BEING APPENDED TO THE NEW NODE?????
  //---------------------------------------------------------
  // nodes.item(i) := the old value (nodes := is a NodeList
  root.replaceChild( neu, nodes.item(i));
  TransformerFactory tFactory     = TransformerFactory.newInstance();
  Transformer transformer         = tFactory.newTransformer();
  DOMSource source                = new DOMSource( doc );
  StreamResult result         = new StreamResult( xml );
  transformer.transform( source, result );
  nodes.item( i ).getParentNode().removeChild( nodes.item(i) );
  </code></pre>
  
  <p>Now this does work to a certain extend, as I mentioned, I guess I am missing the part where the child nodes are being appened, but what I actually wanted to know is, whether there is a really short way to rename the parent node without having to copy everything and replace the whole thing?</p>
  
  <p>Thnx in advance!!!</p>