Code: Select all
$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 "Retrieving all the document:" . "<br />";
echo $doc->saveXML() ;
$doc->save('test2.xml'); // save as file
echo "Retrieving only the title part:" . "<br />";
echo $doc->saveXML($title);Code: Select all
$doc->saveXML(); My output on the console is:
ButRetrieving all the document:
Retrieving only the title part:
Code: Select all
$doc->save('test2.xml');This is what it saved in the test2.xml
I have used this echo $doc->saveXML() ; in many codes, but nowhere it worked for me. I am sorry if i have done any silly mistake,I am new to PHP programming.<?xml version="1.0"?>
<book>
<title>This is the title</title>
</book>
please do help me.
Thanks a lot for your help.
regards
Praveen.