Few Qs about DOMDocument class
Posted: Wed Feb 24, 2010 11:00 am
So I'm not a complete stranger to XML in PHP, but no guru either.
A past project I used the XML DOM to create files, e.g.
Now that I've upgraded my WAMP machine to 5.3.1, I'm seeing that the DOMDocument seems to be the way to go now. A site I found (cant remember where now) said the writers of the DOMDocument class made it "verbose" to make sure everything was possible. It just seems like a lot of code for one measly node.
Just making sure that's the way the library is... and not my lack of understanding of it.
Second, I can't seem to get it to spit out a complete XML document. Even when I try the uber-basic
Nothing is returned, but the php.net site says it's supposed to return the <?xml... declaration. I can add nodes and children and all that jazz, but the XML dec is never printed.
A past project I used the XML DOM to create files, e.g.
Code: Select all
$cRoot = $doc->add_root('library');
$cRoot->set_attribute('type', 'contacts');
//etc
Code: Select all
$entryNode = $dom->createElement('entry');
$idNo = $dom->createAttribute('uid');
$rowid = $dom->createAttribute('dbid');
$entryNode->appendChild($rowid);
$entryNode->appendChild($idNo);
//etc
Second, I can't seem to get it to spit out a complete XML document. Even when I try the uber-basic
Code: Select all
$doc = new DOMDocument('1.0');
echo $doc->saveXML();