Всем привет!
Есть xml4.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<store>
<sku id="7705">
<name>iPod classic</name>
<price>330</price>
<ean>0002520190555</ean>
</sku>
<sku id="1139">
<name>ASUS A626</name>
<price>310</price>
<ean>0502770290391</ean>
</sku>
<sku id="783">
<name>Sony iBook</name>
<price>300</price>
<ean>4506790441392</ean>
</sku>
</store>
и есть скрипт:
<?php
$xmlstr = file_get_contents('xml4.xml');
$store = new SimpleXMLElement($xmlstr);
$dom = new DOMDocument('1.0', 'UTF-8');
$dom_sxe = $dom->importNode($xmlstr);
foreach($store->sku as $sku)
{
echo "id= ".$sku['id'] .'<br />';
echo "name= ".$sku->name .'<br />';
echo "price= ".$sku->price .'<br />';
echo "ean= ".$sku->ean .'<br />';
}
echo"<br/>";
echo"----------------";
echo"<br/>";
//-----------------------------------------Удаление атрибута
//unset($store->sku[3]->name);
//----------------------------------------- Изменить атрибут
//$store->sku[3]->name = 'Big Cliff';
//$store->sku[3] = null;
//removeChild($store->sku[3]);
//-----------------------------------------Добавление Раздела
//$newSku = $store->addChild('sku');
//$newSku->addChild('name', 'Macbook Pro');
//$newSku->addChild('price', '2400');
//$newSku->addChild('ean', '1103610290850');
$store->asXML('xml4.xml');
//-----------------------------------------------------------
echo "name= ".$store->sku[3]->name;
echo"<br/>";
foreach($store->sku as $sku)
{
echo "id= ".$sku['id'] .'<br />';
echo "name= ".$sku->name .'<br />';
echo "price= ".$sku->price .'<br />';
echo "ean= ".$sku->ean .'<br />';
}
echo"<br/>";
echo"----------------";
echo"<br/>";
?>