SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    525
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Saving a new element to XML, without opening the entire file

    i basically have a log (log.xml) that i'm wanting to add a new "row" to everytime something happens in the web application. however, log.xml has the potential to get huge and opening/saving/etc... could start taking up quite a bit of resources.

    i'm just wanting to simply add a new row to the xml file without pulling in the entire xml file. can this be done?

    the log looks something like this...
    <log>
    <entry date="12/18/2007 12:03:42" description="This is a test."></entry>
    </log>

    and i just want to keep adding to the xml without opening up the entire file.

    i also have PHP loaded on the system - so maybe that's an option as well... pass the entry through javascript to PHP and have it write the new entry?

  2. #2
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    525
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i decided to simply use javascript to pass the new data (through ajax) to php and let php handle the writing of the file. (also decided against xml and just a plain text format) the following code will simply place the pointer at the end of the file and write the new entries:

    Code PHP:
     $handle = fopen('/data/audit.log', 'a+');
    fwrite($handle, $the_entry);
    fclose($handle);


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •