stuartmarsh Posted July 13, 2009 Share Posted July 13, 2009 I'm messing with using XML to create a menu system and I am using SimpleXML. I'm want to merge several XML files together to produce the final menu XML. The menu XML looks like this: <menu> <item title="Home" link="home.php" /> <item title="Content" link="content.php" /> </menu> I have another XML called items that looks like this: <menu> <item title="Page1" link="page.php?id=1" addTo="Content" /> <item title="Page2" link="page.php?id=2" addTo="Content" /> </menu> I want to loop through the "items" XML and add a new child under the element that has a title that matches 'addTo'. Is there a quick way of doing this without looping through the menu XML for each item? Something like $xmlMenu->item->"title="content"->addChild($name, $value)? The final output should resemble this: <menu> <item title="Home" link="home.php" /> <item title="Content" link="content.php"> <item title="Page1" link="page.php?id=1" /> <item title="Page2" link="page.php?id=2" /> </item> </menu> Thanks. Link to comment https://forums.phpfreaks.com/topic/165800-simplexml-addchild-to-an-element-with-a-specific-attribute/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.