Changing an XML node value
Posted: Tue Apr 28, 2009 11:17 am
I have a page that needs to change the text within an XML node. Currently I'm using this:
That works fine if there is already text present within the node. For example:
The problem occurs if the node is blank - if it is, the text doesn't get added. For example:
Anyone know of a way round this?
Code: Select all
$docpagedesc = stripslashes($_POST['docpagedesc']);
$main_text = $xml->getElementsBytagName('maintext')->item(0)->firstChild;
$main_text->nodeValue = $docpagedesc;Code: Select all
<maintext>Hello World</maintext>Code: Select all
<maintext />