Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    May 2008
    Posts
    446
    Thanks
    23
    Thanked 5 Times in 5 Posts

    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


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •