Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-11-2012, 09:18 PM   PM User | #1
surreal5335
Regular Coder

 
Join Date: May 2008
Posts: 446
Thanks: 23
Thanked 5 Times in 5 Posts
surreal5335 is an unknown quantity at this point
simplexml addchild problem

I am using the addChild() method with simpleXml, but for some reason I cant seem to close off my <item> node properly, either that or <item> node was not opened properly

Here is my array print out

SimpleXMLElement Object ( [item] => Array ( [0] => SimpleXMLElement Object ( [contract] => 1234 [price] => 4.99 [name] => Image converter ) [1] => SimpleXMLElement Object ( [contract] => 5678 [price] => 9.99 [name] => Silver membership ) ) )


I am trying addChild() in this manner
PHP Code:
$xmlString $_SESSION['cart'].'</cart>';
$cart = new SimpleXMLElement($xmlString);
$items $cart->addChild('item');

            
$items->addChild('contract''1234');
            
$items->addChild('price''14.99');
            
$items->addChild('name''Video Converter'); 
It pulls in the xml file from a session attatchs the closing </cart> node then makes it an object.


further more when I try to echo to the page with a foreach loop, it produces no content, plus the foreach loop is iterating 3 times when there is only 2 items to iterate through

Any thoughts?

Last edited by surreal5335; 06-11-2012 at 10:47 PM.. Reason: new info
surreal5335 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:50 PM.


Advertisement
Log in to turn off these ads.