About the Author  author photo   See All Posts by This Author
PHP Trivia Contest: DOM + Default Namespaces   Given the
following line of PHP:  $xml = DOMDocument::loadXML(   echo
$xml->documentElement->namespaceURI;   Popularity: 30% [?]
There Are 4 Responses So Far. »    1. I suppose it’s cheating to
suggest:      $xpath = new DOMXPath($xml);     echo
$xpath->query('/*[local-name(.)="r"]')->item(0)->namespaceURI;
Section 3 of http://www.w3.org/TR/xml-names/ says:      The
prefix xmlns is used only to declare namespace bindings and is
by definition bound to the namespace name
http://www.w3.org/2000/xmlns/.      Which implies that:      $xm
l->documentElement-
>getAttributeNS('http://www.w3.org/2000/xmlns/','xmlns') should
work, but it doesn't.    2. Yea, XPath is cheating. That’s why I
called out getAttributeNS().      But you’re close enough, as:
Does work. However, I’m not sure if it’s supposed to. :)    3.
Ooh, that’s kooky. I can see why
getAttributeNS(â€™http://www.w3.org/2000/xmlns/â€™,”) wor