I have this simple xml
file :
<iPhone>
<anEvent>
<data1>some Data</data1>
<data2>Some data here </data2>
</anEvent>
<anEvent>
<data1>some Data</data1>
<data2>Some data here </data2>
</anEvent>
</iPhone>
I need to get remove it from this file and write it to another file.
To get the <anEvent>
i want, i do (i just want to transfer only one anEvent) :
$dom = new DomDocument();
$dom->load('myFile.xml');
$myData = $dom->getElementsByTagName('anEvent')->item(0);
I get my at index 0 it's cool. In order to remove it I simply use :
$customRequete->parentNode->removeChild($myData);
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->saveXML();
$dom->save("myFile.xml");
It works, that's cool.
The problem is when I want to write the <anEvent>
to another file.
I know how to write to XML but not using DOM DOCUMENT :
$myNewFile = simplexml_load_file("myNewFile.xml");
$event = $myNewFile->addChild('anEvent');
$data1 = $event->addChild('data1','someData');
$data2 = $event->addChild('data2','some data here');
I was wondering if I could use $myData
from my $dom
in order to write something like :
$myNewFile -> addChild($myData);
$myNewFile->save();
Or do I need to loop into $myData
to get the node values?