Some help with SimpleXML :`(

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi foks,

Could someone lend me a little hand with simpleXML ?
I've been looking at examples in the PHP manual and W3C, i'm at the pinnacle of figuring it out but alas i need a hand from the mailing list dudes.

My aim is to add another "item" node, so i'll start with my XML file called "items.xml"

Item.xml_____________________________

<?xml version="1.0" encoding="iso-8859-1"?>
<clothes>

  <item>
    <name>Red Gloves</name>
    <desc>a pair of red gloves</desc>
    <size>adult</size>
    <price>12.99</price>
  </item>

  <item>
    <name>Snow Boots</name>
    <desc>some snow boots</desc>
    <size>child</size>
    <price>23.99</price>
  </item>

</clothes>
______________________________________


And now the PHP i'm using to create a new "item" node:


$xml = simplexml_load_file('items.xml');

$item = $xml->clothes->addChild('item');
$item->addChild('name', 'blue gloves');
$item->addChild('desc', 'some blue gloves');
$item->addChild('size', 'adult');
$item->addChild('price', '4.99');

______________________________________

The error i'm getting is: "Cannot add child. Parent is not a permanent member of the XML tree"


Help me Gamesmaster!
Matt

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux