title: php editing xml element
body: <p>This is part of the XML I want to edit</p>
  
  <pre><code>&lt;ScrapBook&gt;
    &lt;Event&gt;
     &lt;Name&gt; Name of Event &lt;Name&gt;
     &lt;Other Elements&gt;
    &lt;/Event&gt;
  &lt;ScrapBook&gt;
  </code></pre>
  
  <p>I need to modify the Name of the Event.</p>
  
  <p>I am able to delete the node using remove_child. But I dont know how to add another element at the same spot.</p>
  
  <p>This is my code:</p>
  
  <pre><code>   public function editEventName($oldEventName, $newEventName){
          $xmlDoc = new DOMDocument();
          $xmlDoc-&gt;load($this-&gt;xmlFileName);
          $events = $xmlDoc-&gt;getElementsByTagName("Event");
          foreach($events as $event){
              $eventNames = $event-&gt;getElementsByTagName("Name");
              $eventN = $eventNames-&gt;item(0)-&gt;nodeValue;
              if($oldEventName == $eventN){
                  $nud = $eventNames-&gt;item(0)-&gt;parentNode;
                  $nud-&gt;removeChild($eventNames-&gt;item(0));
  
                  // set name to $newEventName
              }
              $xmlDoc-&gt;saveXML();
      $xmlDoc-&gt;save($this-&gt;xmlFileName);
          }
  </code></pre>