Creating an XML tree using PHP's SimpleXMLElement [closed]

pFlyerb8

New Member
I am experimenting using PHP's own SimpleXMLElement.
I am a newbie at this so please be patient!The following code:\[code\]$sxe = new SimpleXMLElement('<tag></tag>');$movie = $sxe->addChild('movie');$movie->addChild('title', 'PHP2: More Parser Stories');$movie->addChild('plot', 'This is all about the people who make it work.');$characters = $movie->addChild('characters');$character = $characters->addChild('character');$character->addChild('name', 'Mr. Parser');$character->addChild('actor', 'John Doe');$rating = $movie->addChild('rating', '5');$rating->addAttribute('type', 'stars');\[/code\]Produces this XML output (ignore the NEW CHILD element):\[code\]<tag> <NEW_CHILD> <movie> <title>PHP2: More Parser Stories</title> <plot>This is all about the people who make it work.</plot> <characters> <character> <name>Mr. Parser</name> <actor>John Doe</actor> </character> </characters> <rating type="stars">5</rating> </movie> </NEW_CHILD> </tag>\[/code\]However, I want to produce another child element after the tag element, see NEW CHILD.I have tried:\[code\]$movie = $sxe->addChild('movie');$new_element = $sxe->addChild('NEW_CHILD'); \[/code\]but that just creates an closed element at the bottom of the tree.I'm getting confused. Can someone point me in the right direction?
 
Back
Top