Jump to content

adding to an xml file


purencool

Recommended Posts

hi phpfreaks,

 

I am creating a error catching class. What I want to know is there a way to add to bottom of an xml file on the fly. I created the file using php and the intital install  puts the following into the xml file

<logs>
  <error>
    <time>July 15, 2010, 9:22 pm</time>
    <user>Inital install</user>
    <ipAddress>127.0.0.1</ipAddress>
    <errorGen>Log file created</errorGen>
  </error>
</logs>

 

 

What I want to know is the following process correct.

 

Load file (how do I do this?)

goto the bottom of file (how do I do this?)

Insert the following code


                        $error->addChild("time", date("F j, Y, g:i a"));
                        $error->addChild("user", $blah_user);
                        $error->addChild("ipAddress", $_SERVER['REMOTE_ADDR']);
                        $error->addChild("errorGen", $this_is_the_error_generated);
                        $order = $dom->save("logs/log.xml");

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/208079-adding-to-an-xml-file/
Share on other sites

I've been playing around a bit with simplexml, you can find a reference in the manual http://php.net/manual/en/book.simplexml.php

I think that the function simplexml_load_file() will load a simple xml object from a given filename, then you can manipulate this object with the member functions, such as SimpleXMLElement::addChild()

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.