@Cainj Hi man, thanks for your snippet, it does look preety good, but I have some problems with it.
My code looks like this:
<?php
$xml = simplexml_load_file("menu.xml");
$sxe = new SimpleXMLElement($xml->asXML());
$disenoItem = $sxe->addChild("disenoItem");
$disenoItem->addChild("name", "Ed Doe");
$disenoItem->addChild("age", "30");
saveXMLFile($xml, $sxe);
function saveXMLFile($filename, $xml)
{
$dom = dom_import_simplexml($xml)->ownerDocument;
$dom->formatOutput = true;
$fh = fopen($filename,'w');
fwrite($fh,$dom->saveXML());
fclose($fh);
}
?>
What am I doing wrong, actually the FTP trows this error: TypeError: items[x][0] is undefined[]
Thanks if you can check how I used your snippet in order to spot out the problem.
I only delete the world "function" from your snippet right here:
// $sxe->asXML("myXml.xml"); dont need this line
function saveXMLFile($xml, $sxe);
//I changed the above sentence into this:
saveXMLFile($xml, $sxe);
//Cause I think It was an error in your snippet, am I right?
Greetings and thanks in advance for any futher help on this issue.