note 91288 added to domelement.getelementsbytagnamens

From: Date: Thu, 04 Jun 2009 00:36:24 +0000
Subject: note 91288 added to domelement.getelementsbytagnamens
Groups: php.notes 
Request: Send a blank email to php-notes+get-156340@lists.php.net to get a copy of this message
I had some difficulty stripping all default NS attributes for an ns-uri in one shot, the following will work though...first strip the documentElement namespace, then getElementsByTagNameNS() -- the documentation should reflect that the 2nd argument is actually the name of the tag, not the local namespace prefix as I first expected: <?php function strip_default_ns( $xml = null, $ns_uri = 'http://example.com/XML-Foo' ) { $ns_local = ''; $ns_tag = '*'; if ( empty($xml) ) return false; //remove document namespace $dom = new DOMDocument(); $dom->loadXML($xml); $dom->documentElement->removeAttributeNS($ns_uri, $ns_local); //strip element namespaces foreach ( $dom->getElementsByTagNameNS($ns_uri, $ns_tag) as $elem ) { $elem->removeAttributeNS($ns_uri, $ns_local); } return $dom->saveXML(); } $stripped_xml = strip_default_ns($the_xml); ?> $stripped_xml can now take advantage of running XPath queries on it for the NULL namespace. ---- Server IP: 209.41.74.194 Probable Submitter: 63.251.227.210 ---- Manual Page -- http://www.php.net/manual/en/domelement.getelementsbytagnamens.php Edit -- https://master.php.net/note/edit/91288 Del: integrated -- https://master.php.net/note/delete/91288/integrated Del: useless -- https://master.php.net/note/delete/91288/useless Del: bad code -- https://master.php.net/note/delete/91288/bad+code Del: spam -- https://master.php.net/note/delete/91288/spam Del: non-english -- https://master.php.net/note/delete/91288/non-english Del: in docs -- https://master.php.net/note/delete/91288/in+docs Del: other reasons-- https://master.php.net/note/delete/91288 Reject -- https://master.php.net/note/reject/91288 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#156340) next »