Mega Code Archive
Using CDATA sections, or character data sections
createElement ( "html" );
$body = $root->createElement ( "body" );
$script = $root->createElement ( "script" );
$txt = $root->createCDATASection ( "function SubmitForm() {
if (document.myform.name.value == '') {
alert('Name cannot be empty');
document.myform.name.focus();
}
}" );
$script->appendChild ( $txt );
$body->appendChild ( $script );
$html->appendChild ( $body );
$root->appendChild ( $html );
header ( "Content-Type: text/xml" );
echo $root->saveXML ();
?>