Jump to content

append xml file w/php5


sky

Recommended Posts

Hello, first post.

I'm working on a php file that will open an xml file in a DomDocument
then add to the end (or beginning doesn't matter) a new element.

ie...
<people>
    <person>
            <name>Tom</name>
    </person>
    <person>
            <name>Jill</name>
    </person>
</people>

then add a <person> Michelle </person> inside <people>

It seems to add it to the end of the file.
Can somebody help?

Here is my php:


<?php
$dom = new DomDocument;
$dom->formatoutput=true;
$dom->load("theXML.xml");

$newnode= $dom->createElement('person');
$dom->appendChild($newnode);
$tnode= $dom->createTextNode("Michelle");
$newnode->appendChild($tnode);

$dom->save("theXML.xml");
// saves the domDocument into a file called "theXML2.xml"

?>



PLEASE HELP  :-\
Link to comment
https://forums.phpfreaks.com/topic/35910-append-xml-file-wphp5/
Share on other sites

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.