Wednesday, April 11, 2012

Creating/updating an xml file from a mysql database table with php

I have a javascript image gallery which is getting data from an XML file. Im in the process of building a backend function in order for someone else to easy update the gallery. All the data required in the XML file, is available to me from a table in my database.



<?xml version="1.0" encoding="UTF-8"?>
<portfolio>
<items>
<item>
<thumbnail>images/banner001.jpg</thumbnail>
<preview>images/preview.jpg</preview>
<category>banner</category>
<description>Swatch MTV </description>
</item>
<item>
<thumbnail>images/banner002.jpg</thumbnail>
<preview>images/preview.jpg</preview>
<category>banner,campaign</category>
<description>Nike iD</description>
</item>
<item>
<thumbnail>images/banner003.jpg</thumbnail>
<preview>images/preview.jpg</preview>
<category>banner</category>
<description>Sony Handycam</description>
</item>
<item>
<thumbnail>images/banner006.jpg</thumbnail>
<preview>images/preview.jpg</preview>
<category>banner</category>
<description>Statoil App kampagne</description>
</item>
<item>
<thumbnail>images/design006.jpg</thumbnail>
<preview>images/preview.jpg</preview>
<category>web</category>
<description>Hempel Website design</description>
</item>

</items>
</portfolio>


In this regard I have a couple of questions (please keep in mind that im fairly new to php):




  1. which is the better/easier option: update the existing xml file or simply overwrite the entire xml file with newer/updated data?

  2. how do I create the same xml format using php?

  3. I have been looking at both SimpleXML and the DOMDocument. Which one is better/easier to use in my case?



I would be grateful for any help you guys can give me. If posting code, please include a short description/explanation.



Please let me know if you need anything clarified.





No comments:

Post a Comment