Re: XML DOM problem with getAttribute(string)
| From: | Rob Richards | Date: | Wed, 11 Jun 2008 11:14:53 +0000 |
| Subject: | Re: XML DOM problem with getAttribute(string) | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-275228@lists.php.net to get a copy of this message | ||
You might want to put a link to a complete example because $page->documentElement->getAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang'); is how you access it.
Rob
dominussuus@gmail.com wrote:
Thank you, Rob, Unfortunately, that didn't work, either (though I'll keep it in mind). The returned string is still empty. I also unsuccessfully fetched the 'xmlns' attribute using getAttribute(). Interestingly, although hasAttributes(void) returns true, hasAttribute('xmlns'), and hasAttribute(' xml:lang') both return false. On 11/06/2008, Rob Richards <rrichards@cdatazone.org> wrote: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