Jump to content

Add nodes to exsisting XML document...


fagnonk

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.