nicholasstephan Posted December 29, 2008 Share Posted December 29, 2008 How do I concatenate two SimpleXMLElements? For example: I've got: <contacts /> as one SimpleXMLElement, called $contactList, and: <contact> <name>Bob</name> <phone>4852342394</phone> </contact> as another called $bob. Now I want to say $contactList->addChild("contact", $bob);, or something to that effect. Apart from looping through $bob and addChilding each line individually the way they do in the docs, is there any way to accomplish this? Link to comment https://forums.phpfreaks.com/topic/138734-concatenating-simplexmlelements/ Share on other sites More sharing options...
rhodesa Posted December 29, 2008 Share Posted December 29, 2008 Not with SimpleXML...you have to use PHP5's DOM: http://us.php.net/manual/en/domnode.clonenode.php Link to comment https://forums.phpfreaks.com/topic/138734-concatenating-simplexmlelements/#findComment-725355 Share on other sites More sharing options...
nicholasstephan Posted December 29, 2008 Author Share Posted December 29, 2008 really... so I have to: dom_import_simplexml, concat the trees, then simplexml_import_dom... that just sucks... PS: thanks for the quick reply. Link to comment https://forums.phpfreaks.com/topic/138734-concatenating-simplexmlelements/#findComment-725358 Share on other sites More sharing options...
rhodesa Posted December 29, 2008 Share Posted December 29, 2008 or use DOM for the entire thing.... Link to comment https://forums.phpfreaks.com/topic/138734-concatenating-simplexmlelements/#findComment-725360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.