I need sample code for a PHP function that returns XML.
Or even just `<xml />`.
Gumbo
2010-03-25 19:28:50
this doesn't return xml
Tom Haigh
2010-03-25 20:10:03
+5
A:
function foo()
{
return '<root><answer>Not doing your homework for you.</answer></root>';
}
Coronatus
2010-03-25 19:28:02
+1
A:
From PHP manual on DOM
$doc = new DOMDocument('1.0');
// we want a nice output
$doc->formatOutput = true;
$root = $doc->createElement('book');
$root = $doc->appendChild($root);
$title = $doc->createElement('title');
$title = $root->appendChild($title);
$text = $doc->createTextNode('This is the title');
$text = $title->appendChild($text);
echo "Saving all the document:\n";
echo $doc->saveXML() . "\n";
echo "Saving only the title part:\n";
echo $doc->saveXML($title);
Gordon
2010-03-25 20:01:14