Hi all

I'm creating XML with php's native DOMDocument functionality. When I try save the XML it doesn't appear on the server and I can't figure out why.

<?php
// Initiate the XML
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->formatOutput = true;

// Code that creates XML elements and child elements

// Save the XML
echo $doc->saveXML();
$doc->save("file.xml");
?>

The above should work but doesn't. I've made sure that DOM is enabled which it is.

Anyone have any ideas why this wouldn't be saving the XML to the server?

Recommended Answers

All 4 Replies

>> $doc->save("file.xml");

What does this return? FALSE or a number?

>> $doc->save("file.xml");

What does this return? FALSE or a number?

If I remove the echo for the saveXML function then the page is blank. Nothing is returned.

Perhaps you should put some data in it? Also: output how many bytes were written

<?php
// Initiate the XML
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->formatOutput = true;

$root = $doc->createElement('something');
$root = $doc->appendChild($root);


// Save the XML
echo $doc->saveXML();
echo 'Bytes written: '.$doc->save("file.xml");
?>

If this doesn't work and the output is not showing any bytes written, then you probably do not have the privileges to write the file. Are you using Linux or Windows?

Echoing the save function doesn't show anything. I've just had another look at the php.ini file (linux server) and I noticed that the dom section says it's enabled but the Configuration Command shows '--disable-dom'

I'm guessing I'll need to get hold of the hosting company and get them to enable it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.