I have got some code that returns my node from an XML value.
Code: Select all
$xml = simplexml_load_file('books.xml');
$file = "books.xml";
$bodyxpath = "//page[@id='".$pageid."']/body";
$result = $xml->xpath($bodyxpath);
$body = $result[0];
I have read you can change that value by doing
Code: Select all
$result[0]="test";
echo $result[0];
I have also read to replace that back into the XML file you call
Code: Select all
file_put_contents($file, $xml->asXML());
However I cannot get this to work at all. In my testing, I have managed to get it to write back into the XML file in all sorts of ways but all I want to do is to replace the existing content in that node and also preferable within a <![CDATA[]]> tag. Ideally I am using the SimpleXML approach rather than the DOM methods.
Can someone please advise where I am going wrong.
Thanks