Edit XML comment
Posted: Tue Aug 09, 2011 12:17 pm
Hi,
I have this XML file
What I want to do is edit the comment line to the current date when I'll enter a php page.
I know how to load an element and change it but I can't figure out how to load the comment and edit it
this is how I load and edit an element
thanks for the help!!!!
I have this XML file
Code: Select all
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--Created: 8/5/2011 7:04:09 PM-->
<site>
<Visit User="2" DateStamp="08.06.11" TimeStamp="22:24:34">NEW VISIT</Visit>
<Visit User="2" DateStamp="08.06.11" TimeStamp="23:07:48">NEW VISIT/Visit>
</sites>Code: Select all
<!--Created: 8/5/2011 7:04:09 PM-->I know how to load an element and change it but I can't figure out how to load the comment and edit it
this is how I load and edit an element
Code: Select all
//Load XML and set some config
$xml = new DOMDocument('1.0', 'utf-8');
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$getName="$file_name.xml";
$xml->load($getName);
//Get item Element
$element = $xml->getElementsByTagName('site')->item(0);
//Load child elements
$name = $element->getElementsByTagName('Visit')->item(0);
//Change values
$name->nodeValue = 'test';
//Replace old elements with new
$element->replaceChild($name, $name);