Get attributes and values ​​from the xml file

advertisements

I have following xml file:

<ROW>
    <rating>10</rating>
    <answers>Very Satisfied</answers>
    <transaction_date>01/21/2015</transaction_date>
    <date>05/30/2015</date>
    <username>got2bsunny4me</username>
    <link>http://widget.resellerratings.com/store/Amberen/review/#comment8877470</link>
    <comment><![CDATA[my extreme hot flashes became less frequent within a couple weeks, and not as severe.  after 2 months of taking Amberen, I didn't need to take as often.  I've used Amberen before and my hot flashes...]]></comment>
</ROW>
<ROW>
     <rating>10</rating>
     <answers>Very Satisfied</answers>
     <transaction_date>03/23/2015</transaction_date>
     <date>05/18/2015</date>
     <username>musiclvr24</username>
     <link>http://widget.resellerratings.com/store/Amberen/review/#comment8785090</link>
     <comment><![CDATA[Ordering was very easy!  The whole website was very informative and very useful as a health resource.  Thank you very much!]]></comment>
</ROW>

Here is my php file to parse xml file.

<pre>
<?php

$seller_id = 113;
$xml = simplexml_load_string(file_get_contents("http://widget.atings.com/widget/snippet/?seller_id=$seller_id"));
foreach($xml->ROW as $row){
//echo $row,'="',$s,"\"\n"; // to get all rows
 var_dump($row);
   echo '<div class="spans"></div>';
}

//var_dump($xml->ROW) // to get single row
?>
</pre>

I need to get each row's attributes and values displayed on newly created divs for each row. How can I achieve this?


If possible add some main tags at start and end of your XML and rest of your code will work fine...

<document>
<ROW>
<rating>10</rating>
<answers>Very Satisfied</answers>
<transaction_date>01/21/2015</transaction_date>
<date>05/30/2015</date>
<username>got2bsunny4me</username>
<link>http://widget.resellerratings.com/store/Amberen/review/#comment8877470</link>
<comment><![CDATA[my extreme hot flashes became less frequent within a couple weeks, and not as severe.  after 2 months of taking Amberen, I didn't need to take as often.  I've used Amberen before and my hot flashes...]]></comment>
</ROW>

<ROW>
<rating>10</rating>
<answers>Very Satisfied</answers>
<transaction_date>03/23/2015</transaction_date>
<date>05/18/2015</date>
<username>musiclvr24</username>
<link>http://widget.resellerratings.com/store/Amberen/review/#comment8785090</link>
<comment><![CDATA[Ordering was very easy!  The whole website was very informative and very useful as a health resource.  Thank you very much!]]></comment>
</ROW>
</document>