fagnonk Posted May 27, 2009 Share Posted May 27, 2009 I am trying to add a node to an existing xml file using SimpleXMLElement 'addChild' (http://us2.php.net/manual/en/function.simplexml-element-addChild.php). The simple xml documentation explains how to create a new XML document and add nodes but it doesn't tell me how to add nodes to an existing file. My xml file looks like this: <content> <category link="0"> <title>Animals</title> <xml>xml/animals.xml</xml> </category> <category link="1"> <title>Bagua 3 April</title> <xml>xml/bagua.xml</xml> </category> </content> My php wil add extra nodes to the bottom of xml file but it I can't get it to add the nodes in side the content tags: <?php $str = $_SESSION['name']; $file = PREG_REPLACE("/[^0-9a-zA-Z]/i", '', $str); $xml = "\n<category link= >\n<title>".$str."</title>\n<xml>xml/".$file.".xml</xml>\n</category>"; $fp = fopen('galleries.xml', 'a+'); fwrite($fp, $xml); fclose($fp); ?> Any suggestions? Link to comment https://forums.phpfreaks.com/topic/159813-add-nodes-to-exsisting-xml-document/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.