# Help needed. reading/writing XML

**URL:** <https://forum.kirupa.com/t/help-needed-reading-writing-xml/279315>\
**Category:** programming\
**Created:** [January 13, 2009, 11:17am UTC](https://forum.kirupa.com/t/help-needed-reading-writing-xml/279315 "2009-01-13T11:17:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arundracula](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@arundracula](https://forum.kirupa.com/u/arundracula)\
**Post date:** [January 13, 2009, 11:17am UTC](https://forum.kirupa.com/t/help-needed-reading-writing-xml/279315/1 "2009-01-13T11:17:58Z")

</div>

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.

```auto

<?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>

```
