Howto: Remove XML, doctype and top-level namespace declarations from DOMDocument
| From: | Victor Engmark | Date: | Sat, 29 Mar 2008 20:10:58 +0000 |
| Subject: | Howto: Remove XML, doctype and top-level namespace declarations from DOMDocument | ||
| Groups: | php.xml.dev | ||
| Request: | Send a blank email to php-xml-dev+get-608@lists.php.net to get a copy of this message | ||
Hi all,
This silly little problem took quite a while to figure out without using any regular expression hacks, so here goes (example using XHTML namespace):
// Initialize
$doc = new DOMDocument;
$doc->load('somefile.xhtml');
// Remove XHTML namespace declaration
$doc->documentElement->removeAttributeNS('http://www.w3.org/1999/xhtml',
'');// Get the XML contents without XML and doctype declarations $text => $doc->saveXML($doc->documentElement)) // Now you can use this to e.g. process several XML documents in XSLT $proc->setParameter(NULL,
array_merge($other_params, array('text' => $text));
PS: I tried to submit this as a PHP documentation note, but my IP is blocked for some reason.
PPS: Coming soon to a website near you ;)
--
Victor Engmark