Re: XML DOM problem with getAttribute(string)
| From: | Rob Richards | Date: | Wed, 11 Jun 2008 09:31:36 +0000 |
| Subject: | Re: XML DOM problem with getAttribute(string) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-275224@lists.php.net to get a copy of this message | ||
Borden Rhodes wrote:
I'm having a pig of a time trying to figure this one out: I have an XHTML document which I've loaded into a DOMDocument because I want to add more tags to it. However, since I live in a bilingual country, I want to get the document's xml:lang attribute so I know what language to add my new tags in. I want to write $lang = $page->documentElement->getAttribute('xml:lang'); OR $lang = $page->documentElement->getAttributeNS('xml', 'lang'); but both of these return empty strings, indicating that it cannot find the xml:lang attribute. And yet, $page->documentElement->hasAttributes() returns true and $page->documentElement->attributes->getNamedItem('xml:lang')->nodeValue; works correctly. So why doesn't my preferred code?The xml prefix is bound to the http://www.w3.org/XML/1998/namespace namespace. $lang = $page->documentElement->getAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang'); Rob