<?php
$s = '<?xml version="1.0" encoding="UTF-8"?>
<products>
<product id="p02">
<name>Name 2</name>
<price currency="USD">200</price>
</product>
<product id="p03">
<name>Name 3</name>
<price currency="EUR">400</price>
</product>
<product id="p04">
<name>name 4</name>
<price>11</price>
</product>
<product id="p05">
<name>name 5</name>
<price>999</price>
</product>
</products>';
$products = simplexml_load_string($s);
foreach($products->product as $product){
echo 'id: ' .$product['id'];
echo '<br>name: ' .$product->name;
echo '<br>price: ' .$product->price;
echo '<br>-------------------------<br>';
}
?>
id: p02
name: Name 2
price: 200
-------------------------
id: p03
name: Name 3
price: 400
-------------------------
id: p04
name: name 4
price: 11
-------------------------
id: p05
name: name 5
price: 999
-------------------------