PHP help - writing to an XML file

Soldato
Joined
1 Feb 2006
Posts
8,188
Hi, im writing a script that will accept content from a web form and add it to an xml file. This will make up an RSS feed so I need to be able to add articles to a certain positiion in the document based on tags. In RSS each article is enclosed within <item> tags and the items are preceeded by some header information. Using php, how can i search (for tags) for the correct location in the file where I can add the new content?
I know this is possible using XML DOM and functions like appendChild but I am not sure how this would be done in PHP.
Thanks
 
thanks for the help. I had a look at those links and so far I have came up with this:

Code:
<?php	
	$doc = new DOMDocument();
	
	$doc->load('RSS/sample_rss.xml');
	
	$element = $doc->createElement('item', 'This is the new test element!');
	
	$doc->appendChild($element);
	
	echo $doc->saveXML();
?>

This script adds a new tag at the very end of the file but I need to add it after a tag named 'channel'. How can I do this instead of adding it to the end of the file? Had a look on the PHP site but couldn't find anything.
 
Back
Top Bottom