Hi folks,
I am using DOMDocument to create a xml file...but I don't quiet understand about the difference between the DOMDocument->save() and DOMDocument->saveXML()....
From what I have read in the documentation about these I only noted the difference that the saveXML() method doesn't output to the file, while the save() method does output a file..., please correct me if I am wrong...
http://www.php.net/manual/en/function.d ... t-save.php
http://www.php.net/manual/en/function.d ... avexml.php
So, which one is better to use ??? Or should I use both ?
Many thanks,
Christian
When to use DOMDocument->save() OR saveXML() ?
Moderator: General Moderators
- christian_phpbeginner
- Forum Contributor
- Posts: 136
- Joined: Sat Jun 03, 2006 2:43 pm
- Location: Java
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
I suspect saveXML() is what you're looking for.
The save() method writes a file to the filesystem
The saveXML() method echoes the XML to the output (like the browser, or you can capture it as a variable)
you might want to save the xml to a variable if you plan on transforming it.
Cheers,
Kieran
The save() method writes a file to the filesystem
Code: Select all
$doc = new DOMDocument;
//.... add some nodes....
$doc-->save('path/to/file.xml'); // saves the xml as a file on the server
// maybe you want the user to download the file?
echo '<a href="path/to/file.xml">download the xml file</a>';Code: Select all
$doc = new DOMDocument;
//.... add some nodes....
$xml_as_a_string = $doc-->saveXML(); // saves the xml in the variable
// --OR--
$doc-->saveXML(); // writes the xml to the browserCheers,
Kieran