Forum Moderators: coopster

Message Too Old, No Replies

Updating an XML file

         

ag_47

5:16 am on May 6, 2008 (gmt 0)

10+ Year Member



Hi,

I'm using xml_parser() methods to read and display some info stored in an xml file. Now I'm having trouble actually updating the file automatically - with PHP. Could someone advise how I can add data to the BEGINNING of an xml file. (There are about 3 simple tags, nothing special actually)

barns101

2:07 pm on May 6, 2008 (gmt 0)

10+ Year Member



I think you'll need to open the file with fopen() [php.net] in read/write mode with the file pointer at the beginning. You can then use frwite() [php.net] and fclose() [php.net] to write to the file and save it.

ag_47

3:36 pm on May 6, 2008 (gmt 0)

10+ Year Member



Yes, but that would over-write the existing data. I'm trying to write to the beginning of the file. The only way I see around this is reading the whole file and sticking that to whatever I'm trying to add then write the result back in.. But that's no good, especially if the file starts getting big.

What I'm basically archive is being able to read the latest addition first. In other words, I could write new data to the end, but then I'd have to read from end..

Since I'm not working with random files, I'm using XML, I was hoping there'd be an easier way to do this.