Page 1 of 1

Changing an XML node value

Posted: Tue Apr 28, 2009 11:17 am
by The Omen
I have a page that needs to change the text within an XML node. Currently I'm using this:

Code: Select all

$docpagedesc = stripslashes($_POST['docpagedesc']);
 
$main_text = $xml->getElementsBytagName('maintext')->item(0)->firstChild;
$main_text->nodeValue = $docpagedesc;
That works fine if there is already text present within the node. For example:

Code: Select all

<maintext>Hello World</maintext>
The problem occurs if the node is blank - if it is, the text doesn't get added. For example:

Code: Select all

<maintext />
Anyone know of a way round this?