0

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?

2
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by Venom Rush
0

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

What does this return? FALSE or a number?

0

>> $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.

Edited by Venom Rush: n/a

0

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?

Edited by n_e: n/a

0

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.

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.