title: Append and prepend text nodes to a HTML element using DOM?
body: <p>Here is my HTML code</p>
  
  <pre><code>&lt;html&gt; 
      &lt;body&gt;
          &lt;div&gt;A sample block &lt;div&gt;and child block&lt;/div&gt;&lt;/div&gt;    
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>How can I use DOM to append and prepend text nodes to the BODY elements without hurting its siblings?</p>
  
  <pre><code>$dom = new DOMdocument();    
  @$dom-&gt;loadHTML($html);    
  $xpath = new DOMXPath($dom);    
  $body = $xpath-&gt;query('//body')-&gt;item(0);    
  </code></pre>
  
  <p>like this</p>
  
  <pre><code>&lt;html&gt; 
      &lt;body&gt;
          Newly prepended text
          &lt;div&gt;A sample block &lt;div&gt;and child block&lt;/div&gt;&lt;/div&gt;
          Newly appended text    
      &lt;/body&gt;
  &lt;/html&gt;  
  </code></pre>