I have an xml sheet I have created and converted into an object with simpleXml. My problem is that when I do a count() on the <item> tag I always get 1. When I tried to view xml in its own page I get this error
XML Parsing Error: no element found
So I ran the xml string through htmlSpecialChars and it produced this on the screen for me.
Code:
<?xml version="1.0" standalone="yes"?>
<cart>
<item id="0"><product>dvd</product><contract>2133782</contract><price>39.99</price><name>DVD Creator</name></item>
<item id="1"><product>music</product><contract>2133786</contract><price>29.99</price><name>Music Editor</name></item>
<item id="1"><product>image</product><contract>2131570</contract><price>4.99</price><name>Image membership</name></item>
</cart>
When I do a print_r() on the object, this is what I get:
Code:
SimpleXMLElement Object ( [item] => Array (
[0] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 0 ) [product] => dvd [contract] => 2133782 [price] => 39.99 [name] => DVD Creator )
[1] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 1 ) [product] => music [contract] => 2133786 [price] => 29.99 [name] => Music Editor )
[2] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 1 ) [product] => image [contract] => 2131570 [price] => 4.99 [name] => Image membership )
)
The method I am adding items to my object is by:
PHP Code:
$items = $cart->addChild('item');
$index = $cart->count();
$items->addAttribute('id', $index);
$items->addChild('contract', '2133782');
$items->addChild('price', '39.99');
$items->addChild('name', 'DVD Creator');
The $index always returns 1 as I mentioned before. So it seems that the <item> tag is only getting created once or the rest are not getting recognized.
What about it am I missing? Would the spaces inbetween the tags cause this problem?