title: Cakephp Xml to Array to Database
body: <p>this is the first time using CakePHP's XML functions.</p>
  
  <p>I have set up this model:</p>
  
  <pre><code>&lt;?php
  class Importer extends AppModel {
      var $name = 'Importer';
      var $useTable = false;
  
      function import_deals(){
          // import XML class
          App::import('Xml');
  
          // your XML file's location
          $file = "../webroot/files/datafeed_114532.xml";
  
          // now parse it
          $parsed_xml =&amp; new XML($file);
          $parsed_xml = Set::reverse($parsed_xml); // this is what i call magic
  
          // see the returned array
          debug($parsed_xml);
      }
  }
  </code></pre>
  
  <p>Controller: </p>
  
  <pre><code>&lt;?php
  class ImporterController extends AppController {
  
      var $name = 'Importer';
      var $uses = array('Importer', 'City', 'Deal', 'Partner');
  
      function import_deals($parsed_xml) {
          $this-&gt;loadModel('Importer');
          $deals = $this-&gt;Importer-&gt;find('all');
  
          $this-&gt;set('deals', $deals);
      }
  }
  </code></pre>
  
  <p>The view I am not sure about because I basically want it to put the XML data into the database. The XML array looks like:</p>
  
  <pre><code>Array (
      [MerchantProductFeed] =&gt; Array (
          [Merchant] =&gt; Array (
              [0] =&gt; Array (
                  [id] =&gt; 2891
                  [Prod] =&gt; Array (
                      [0] =&gt; Array (
                          [id] =&gt; 175029851
                          [web_offer] =&gt; yes
                          [Text] =&gt; Array (
                              [name] =&gt; London South: 60%   Off Takeaways From Just-Eat
                              [desc] =&gt; £6 for £15 Worth of Takeaways From Over 1000 London Eateries with Just-Eat
                              [promo] =&gt; 60 %
                          )
                          [Uri] =&gt; Array (
                              [awTrack] =&gt; http://www.awin1.com/pclick.php?p=175029851&amp;a=114532&amp;m=2891
                              [mImage] =&gt; http://static.groupon.co.uk/44/30/1311759403044.jpg
                          )
                          [Price] =&gt; Array (
                              [rrp] =&gt; 15.00
                          )
                          [Cat] =&gt; Array (
                              [awCatId] =&gt; 100
                              [awCat] =&gt; Bodycare &amp; Fitness
                              [mCat] =&gt; Deals
                          )
                          [brand] =&gt; Array ()
                          [valFrom] =&gt; 2011-07-29
                          [valTo] =&gt; 2011-10-29
                      )
                      [1] =&gt; Array (
                          [id] =&gt; 175030161
                          [web_offer] =&gt; yes
                          [Text] =&gt; Array (
                              [name] =&gt; Essex: Up to 70% Off Treatment and Cut and Blowdry OR Half Head Highlights or Colour
                              [desc] =&gt; Cut, Blow Dry and Paul Mitchell Treatment (£18) Or Add Half Head of Highlights or Colour (£34) at Cube (Up to 70% Saving)
                              [promo] =&gt; 70 %
                          )
                          [Uri] =&gt; Array (
                              [awTrack] =&gt; http://www.awin1.com/pclick.php?p=175030161&amp;a=114532&amp;m=2891
                              [mImage] =&gt; http://static.groupon.co.uk/53/51/1311615285153.jpg
                          )
                          [Price] =&gt; Array (
                              [rrp] =&gt; 60.00
                          )
                          [Cat] =&gt; Array (
                              [awCatId] =&gt; 100
                              [awCat] =&gt; Bodycare &amp; Fitness
                              [mCat] =&gt; Deals
                          )
                          [brand] =&gt; Array ()
                          [valFrom] =&gt; 2011-07-29
                          [valTo] =&gt; 2011-10-28
                      )
                      ....
  </code></pre>
  
  <p>Any help would be appreciated, even if you can point me in right direction :) Thanks guys</p>
  
  <p>Dave</p>