The following code produces the XML file that I am after.
$dom = new DOMDocument('1.0', 'UTF-8');
// pretty formatting
$dom->formatOutput = true;
// create root element
$root = $dom->createElement('Poem');
$root->setAttribute('object_id', '542');
$dom->appendChild($root);
// create title element
$title = $dom->createElement('title');
$root->appendChild($title);
// create a node for the title element
$text = $dom->createTextNode('The Unknown Poem');
$title->appendChild($text);
// save xml as string
$test = $dom->saveXML();
echo($test);
$dom->save('testDOM.xml');
I get testDom.xml
contaning the details that I need. However, the echo($test);
prints nothing.
What might be the cause I wonder? I tried print_r()
too. Any suggestions?
Additional Information
XAMPP (on Win 8) is running fine. Apache is running.
I can echo 'other string values';
.