title: How to read XML file data with Php?
body: <p>I have xml file in the following format.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;rss version="2.0" xmlns:g="http://base.google.com/ns/1.0"&gt;  
    &lt;channel&gt;  
    &lt;title&gt;Data feed Title&lt;/title&gt;
    &lt;link&gt;http://www.amarchitrakatha.com/in/&lt;/link&gt;
    &lt;description&gt;Data feed description.&lt;/description&gt;
      &lt;item&gt;ACKKALID0577
      &lt;g:id&gt;&lt;![CDATA[ACKKALID0577]]&gt;&lt;/g:id&gt;
      &lt;title&gt;&lt;![CDATA[Kalidasa]]&gt;&lt;/title&gt;
      &lt;link&gt;&lt;![CDATA[http://www.amarchitrakatha.com/in/kalidasa?fee=19&amp;fep=1147]]&gt;&lt;/link&gt;
      &lt;g:price&gt;70.00&lt;/g:price&gt;
      &lt;g:sale_price&gt;&lt;/g:sale_price&gt;
      &lt;description&gt;&lt;![CDATA[Kalidas Owes His Fame To His Sanksrit Play Abhijnana-Shakuntala (Shakuntala Recognised By The Token Ring), The Long Epic Poem Kumara-Sambhava (Birth Of Kumara) And The Lyric Poem Meghaduta (Cloud Messenger). Kalidasa, Who Lived Some Time In The Middle Of The 4Th And Early 5Th Centuries A.D., Has Left No Account Of His Life. According To Popular Legend, He Owed His Ingenuity As Much To Goddess Kaliâ€™S Blessings As To His Own Talents.]]&gt;&lt;/description&gt;
      &lt;g:product_type&gt;&lt;![CDATA[Amar Chitra Katha  &gt; Visionaries &gt; Singles]]&gt;&lt;/g:product_type&gt;
      &lt;g:google_product_category&gt;&lt;![CDATA[]]&gt;&lt;/g:google_product_category&gt;
      &lt;g:image_link&gt;&lt;![CDATA[http://www.amarchitrakatha.com/media/catalog/product/K/A/KALIDASA_0__5.jpg]]&gt;&lt;/g:image_link&gt;
      &lt;g:condition&gt;new&lt;/g:condition&gt;
      &lt;g:availability&gt;in stock&lt;/g:availability&gt;
      &lt;g:shipping_weight&gt;0.09 kg&lt;/g:shipping_weight&gt;
      &lt;g:brand&gt;&lt;![CDATA[]]&gt;&lt;/g:brand&gt;
      &lt;g:mpn&gt;&lt;![CDATA[ACKKALID0577]]&gt;&lt;/g:mpn&gt;
      &lt;g:gtin&gt;&lt;![CDATA[]]&gt;&lt;/g:gtin&gt;
    &lt;/item&gt;
    &lt;item&gt;ACKPRITH1413
      &lt;g:id&gt;&lt;![CDATA[ACKPRITH1413]]&gt;&lt;/g:id&gt;
      &lt;title&gt;&lt;![CDATA[Prithviraj Chauhan]]&gt;&lt;/title&gt;
      &lt;link&gt;&lt;![CDATA[http://www.amarchitrakatha.com/in/prithviraj-chauhan?fee=19&amp;fep=1150]]&gt;&lt;/link&gt;
      &lt;g:price&gt;70.00&lt;/g:price&gt;
      &lt;g:sale_price&gt;&lt;/g:sale_price&gt;
      &lt;description&gt;&lt;![CDATA[Jaichand Was Furious! His Daughter Samyogita Had Eloped With Prithviraj Chauhan, The Warrior King Of Delhi. She, Like Many Others, Was Smitten By Tales Of His Daring, His Nobility And His Sense Of Honour. Though The Young Coupleâ€™S Happiness Was Doomed, Even In His Dying Hour, It Was The Brave Prithviraj Who Chose How His Life Should End.]]&gt;&lt;/description&gt;
      &lt;g:product_type&gt;&lt;![CDATA[Amar Chitra Katha  &gt; Brave Hearts Story &gt; Singles]]&gt;&lt;/g:product_type&gt;
      &lt;g:google_product_category&gt;&lt;![CDATA[]]&gt;&lt;/g:google_product_category&gt;
      &lt;g:image_link&gt;&lt;![CDATA[http://www.amarchitrakatha.com/media/catalog/product/P/R/PRITHVIRAJ_CHAUHAN_0__4.jpg]]&gt;&lt;/g:image_link&gt;
      &lt;g:condition&gt;new&lt;/g:condition&gt;
      &lt;g:availability&gt;in stock&lt;/g:availability&gt;
      &lt;g:shipping_weight&gt;0.09 kg&lt;/g:shipping_weight&gt;
      &lt;g:brand&gt;&lt;![CDATA[]]&gt;&lt;/g:brand&gt;
      &lt;g:mpn&gt;&lt;![CDATA[ACKPRITH1413]]&gt;&lt;/g:mpn&gt;
      &lt;g:gtin&gt;&lt;![CDATA[]]&gt;&lt;/g:gtin&gt;
    &lt;/item&gt;
   &lt;/channel&gt;
  &lt;/rss&gt;
  </code></pre>
  
  <p>By using <code>simplexml_load_file</code> I am not getting data of item. How to parse this type of format XML with PHP? I want to get the data of all items like g:id, title, link etc.</p>
  
  <pre><code>if (file_exists('Sample.xml')) {
  $xml = simplexml_load_file('Sample.xml');
  echo '&lt;pre&gt;';
  print_r($xml-&gt;channel);
  echo '&lt;/pre&gt;';
  } else {
  exit('Failed to open Sample.xml.');
  }
  </code></pre>
  
  <p>And m getting result as </p>
  
  <pre><code>SimpleXMLElement Object
  (
  [title] =&gt; Data feed Title
  [link] =&gt; http://www.amarchitrakatha.com/in/
  [description] =&gt; Data feed description.
  [item] =&gt; Array
      (
          [0] =&gt; ACKKALID0577
  
          [1] =&gt; ACKPRITH1413
      )
  )
  </code></pre>
  
  <p>I have to store data of items in specific variables.</p>