Jump to content

How to generate XML files?


lovesmith

Recommended Posts

well i have a form, it have three fields, txtword(textbox), image(file field) and sound(file field).

The format i want is like this

<?xml version="1.0" encoding="utf-8"?>
<photos path="images/">
   <photo name="photo1" url="1.jpg" link="one" sound="1.mp3">This is photo 1</photo>
   <photo name="photo2" url="2.jpg" link="two" sound="2.mp3">This is photo 2</photo>
   <photo name="photo3" url="3.jpg" link="three" sound="3.mp3">This is photo 3</photo>
   <photo name="photo4" url="4.jpg" link="four" sound="4.mp3">This is photo 4</photo>
   <photo name="photo5" url="5.jpg" link="five" sound="5.mp3">This is photo 5</photo>
</photos>

 

in above code the child node is added each time the form is submitted. parent node is created only when there is no xml generated before. in above code for time being neglect name and link attribute. other attributes holds value from the form data.

Any body ?

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/106430-how-to-generate-xml-files/
Share on other sites

SimpleXML is probably your best bet.

 

1) Check to see if the file exists. If it does, simplexml_load_file($file), if it doesn't, simplexml_load_string('<photos path="images/"></photos')

2) Add the new photo element using the addChild() method

3) Save the new XML with the asXML($file) method

SimpleXML is probably your best bet.

 

1) Check to see if the file exists. If it does, simplexml_load_file($file), if it doesn't, simplexml_load_string('<photos path="images/"></photos')

2) Add the new photo element using the addChild() method

3) Save the new XML with the asXML($file) method

Thanks a ton man

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.