ต่อโจทย์ xml ต่อให้หน่อยครับ ต่อไม่ได้แล้วงง

ตย. file item.xml
<product id="1080001" name="Small box" price="135" is_best="true">
<component item_id="22000" count="1"/>
</product>
<product id="1080002" name="Middle box" price="270" is_best="true">
<component item_id="22001" count="1"/>
</product>
<product id="1080003" name="Large box" price="405" is_best="true">
<component item_id="22002" count="1"/>
</product>
----------
ไฟล์ php
<?php
// <product id="" name="" category="" price="" is_event="" is_best="" is_new="" on_sale="" sale_start_date="" sale_end_date="">
// <component item_id="" count=""/>
$dom = new DomDocument;
$dom->preserveWhiteSpace = FALSE;
$dom->load("item.xml");
$params = $dom->getElementsByTagName('product');
//var_dump($params);
$count = $params->length;
echo  $count." Records.<hr width='15%' align='left'>";

foreach ($params as $param) {
    echo "id = ".$param -> getAttribute('id').' <br>';
    echo "name = ".$param -> getAttribute('name').' <br>';
    echo "catagory = ".$param -> getAttribute('catagory').' <br>';
    echo "price = ".$param -> getAttribute('price').' <br>';
    echo "is event = ".$param -> getAttribute('is_event').' <br>';
    echo "is best = ".$param -> getAttribute('is_best').' <br>';
    echo "is new = ".$param -> getAttribute(' is_new').' <br>';
    echo "on sale = ".$param -> getAttribute('on_sale').' <br>';
    echo "sale_start_date = ".$param -> getAttribute('sale_start_date').' <br>';
    echo "sale_end_date = ".$param -> getAttribute('sale_end_date').' <br><br>';    
}
?>

ตรงส่วน component ผมจะเขียนอย่างไงครับให้มี output ออกมา
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่