title: XML search for a node from an array and add new data to a new node
body: <p>From this tutorial - section on Adding nodes over at PHPFreaks, I did post over there but have had no replies strange as the tutorial was written by them.</p>
  
  <p><a href="http://www.phpfreaks...ndling-xml-data" rel="nofollow">http://www.phpfreaks...ndling-xml-data</a></p>
  
  <p>When I use my xml file it creates the node but does not insert the new data. There are no page errors. I'm sure I have just missed something very simple and after hours of trying I will now bow down and ask for help.</p>
  
  <p><em><strong>This is the script I'm using</em></strong></p>
  
  <pre><code>&lt;?php
  // isbn =&gt; pages
  $page_numbers = array(
                       '1234' =&gt; '654', // insert data into catparent node
                       '5678' =&gt; '789', // insert data into catparent node
                  );
  $dom = new DOMDocument();
  $dom-&gt;load('edtest.xml');
  $xpath = new DOMXPath($dom);
  $items = $xpath-&gt;query('item');
  foreach($items as $item)
  {
    $item-&gt;appendChild($dom-&gt;createElement('catparent', $page_numbers[$item-&gt;getAttribute('catcode')]));
  }
  $dom-&gt;save('edtest_new.xml');
  ?&gt;
  </code></pre>
  
  <p><em><strong>My XML</em></strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;items&gt;
  &lt;item&gt;
  &lt;catcode&gt;1234&lt;/catcode&gt;
  &lt;catdesc&gt;Systems - System Bundles&lt;/catdesc&gt;
  &lt;price_cost&gt;999.95&lt;/price_cost&gt;
  &lt;price_sell&gt;999.95&lt;/price_sell&gt;
  &lt;/item&gt;
  &lt;/items&gt;
  </code></pre>
  
  <p><em><strong>Output XML</em></strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;items&gt;
  &lt;item&gt;
  &lt;catcode&gt;1234&lt;/catcode&gt;
  &lt;catdesc&gt;Systems - System Bundles&lt;/catdesc&gt;
  &lt;price_cost&gt;999.95&lt;/price_cost&gt;
  &lt;price_sell&gt;999.95&lt;/price_sell&gt;
  
  &lt;catparent&gt;&lt;/catparent&gt; // it creates but does not insert required data
  
  &lt;/item&gt;
  &lt;/items&gt;
  </code></pre>
  
  <p>It runs the script creates the required node, but it does not insert the required data.  The object of the script is to find <code>&lt;catcode&gt; = 1234</code> and add a new <code>&lt;catparent&gt; &lt;/catparent&gt;</code> with required data from the array.</p>
  
  <p>If there is a better way to achieve the result or just the correction needed.</p>
  
  <p>Thanks </p>