Connecting Tech Pros Worldwide Help | Site Map

Modifying an XML file with PHP

  #1  
Old June 19th, 2009, 06:14 AM
mikek12004's Avatar
Familiar Sight
 
Join Date: Sep 2008
Location: Athens, Greece
Posts: 181
I have an XML file representing categories like this
Expand|Select|Wrap|Line Numbers
  1. <?xml version='1.0' encoding='utf-8' ?>
  2. <bank>
  3. <img>
  4.     <src>img/GF0813-1_thumb.jpg</src>
  5.     <title>classicΙ</title>
  6.     <caption>Click here</caption>
  7.     <link>main.php?page=2&amp;id=125</link>
  8.     <target>_self</target>
  9. </img>
  10. <img>
  11.     <src>img/PBE0720008_thumb.jpg</src>
  12.     <title>BULLETS</title>
  13.     <caption>Click here</caption>
  14.     <link>main.php?page=2&amp;id=117</link>
  15.     <target>_self</target>
  16. </img>
  17. </bank>
  18.  
where each <img></img> represents a category which has an image (<src>), title (<title>), caption (<caption>), link and target of that link.
Now when I add a category its easy to open the xml like an ordinary file and add the corresponding <img> at the end, but when I delete/modify a category I have to check where the corresponding <img></img> exists (each category/<img> has a unique id going into the <link>) and modify that how can I do it? (My initial idea involves using explode with </img>, is there a better way to handle xml through PHP?)
  #2  
Old June 19th, 2009, 06:52 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,487
Provided Answers: 9

re: Modifying an XML file with PHP


Quote:
Originally Posted by mikek12004 View Post
and modify that how can I do it? (My initial idea involves using explode with </img>, is there a better way to handle xml through PHP?)
of course. PHP comes with a bundle of XML manipulation functionality:
SimpleXML
DOM
SAX type parsers (XMLReader, XMLWriter, XML Parser)
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
using xmlreader and xmlwriter to modify and rewrite a feed? jrd answers 0 June 27th, 2008 05:16 PM
create html from flat file lxyone@googlemail.com answers 15 June 27th, 2008 05:15 PM
Need help building PHP3 with MySQL as DSO on Solaris 8, PHP4 + MySQL built and loads fine pancho@acadia.net answers 2 July 17th, 2005 07:44 AM
creating XML with embedded PHP Troy answers 6 July 17th, 2005 03:20 AM