Help needed. reading/writing XML

How can we create this type of XML in PHP.
I did this with repeated typing with DOM. But it did wrong with when receiving variables.
i.e., consider this is like a forum XML. the <topic/> are topics and inside all are posts.

So if someone posts inside a topic, we have to go inside it and add a <post/> tag with the name attribute.
I don’t know how to edit a specific topic.

Also if someone posts a NEW TOPIC, we have to create a third <topic/> tag and create a <post/> tag.
This is also “I don’t know”.

Please help…Also please tell how to send the variables into the script to edit this XML. For. eg: in an array or something like that.



<?xml version="1.0" encoding="iso-8859-1"?>
<forum>
	<topic title="1_topic_title" name="11name">
		<post name="11name">this is post 1 of topic 1 </post>
		<post name="12name">this is post 2 of topic 1 </post>
	</topic>
	<topic title="2_topic_title" name="21name">
		<post name="21name">this is post 1 of topic 2</post>
		<post name="22name">this is post 2 of topic 2</post>
	</topic>
</forum>