PHPにおけるXMLタググループの属性

ここで、複数のタグに属性があるとします:

test.xml<root>
  <tag attr="val1">text1</tag>
  <tag attr="val2">text2</tag>
  <tag attr="val3">text3</tag>
</root>

これらのタグのテキストを取得してみましょう:

index.php<?php
  foreach ($xml->tag as $tag) {
    echo $tag; // 'text1', 'text2', 'text3'
  }
?>

次に、属性値を取得します:

index.php<?php
  foreach ($xml->tag as $tag) {
    echo $tag['attr']; // 'val1', 'val2', 'val3'
  }
?>
Задание 1

以下のXMLが与えられています:

html<root>
  <product cost="100" amount="3">
    prod1
  </product>
  <product cost="200" amount="4">
    prod2
  </product>
  <product cost="300" amount="5">
    prod3
  </product>
</root>

各製品の名前、価格、数量を画面に表示してください。