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');

// create title element
$title = $dom->createElement('title');

// create a node for the title element
$text = $dom->createTextNode('The Unknown Poem');

// save xml as string
$test = $dom->saveXML();

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';.

Edited by ikel: Clarity, politeness, more info

2 Years
Discussion Span
Last Post by diafol

Not really looked hard. Which browser are you using? SOme browser do not display XML at all - have a look in page/view source of the browser to see if it's there.

Edited by diafol


I'm sorry, I didn't look hard enough.
I've just tested itwith IE, Fire Fox and Chrome. I see nothing on screen. Page view/source option with these browsers did not reveal the output of echo XML. But, I ended up with the correct XML file on server.

I can open and see the content of the XML file correctly on IE, Fire Fox and Chrome.

If I execute this code in http://sandbox.onlinephpfunctions.com/ it prints echo correctly.
If I execute this code in http://phptester.net/, it does not print echo output.

Hence, I'm puzzled.


On line 20, I did the following and can see the echo'd code just fine.



On line 20, I did the following and can see the echo'd code just fine.

If that's the case, then it's as I originaly thought.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.