title: How to replace the text of a node using DOMDocument
body: <p>This is my code that loads an existing XML file or string into a DOMDocument object:</p>
  
  <pre><code>$doc = new DOMDocument();
  $doc-&gt;formatOutput = true;
  
  // the content actually comes from an external file
  $doc-&gt;loadXML('&lt;rss version="2.0"&gt;
  &lt;channel&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;description&gt;&lt;/description&gt;
      &lt;link&gt;&lt;/link&gt;
  &lt;/channel&gt;
  &lt;/rss&gt;');
  
  $doc-&gt;getElementsByTagName("title")-&gt;item(0)-&gt;appendChild($doc-&gt;createTextNode($titleText));
  $doc-&gt;getElementsByTagName("description")-&gt;item(0)-&gt;appendChild($doc-&gt;createTextNode($descriptionText));
  $doc-&gt;getElementsByTagName("link")-&gt;item(0)-&gt;appendChild($doc-&gt;createTextNode($linkText));
  </code></pre>
  
  <p>I need to overwrite the value inside the title, description and link tags. The Last three lines in the above code are my attempt at doing so; but seems like if the nodes are not empty then the text will be "appended" to existing content. How can I empty the text content of a node and append new text in one line.</p>