W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2000

question regarding Element.getAttributeNS()

From: Garret Wilson <garret@globalmentor.com>
Date: Fri, 22 Dec 2000 07:01:31 -0800
Message-ID: <003d01c06c28$12254d20$7245a640@pacbell.net>
To: "www-dom list" <www-dom@w3.org>
Thanks to everyone who replied earlier to clear up that attributes with no
namespace prefix specified will have a null namespace URI under DOM Level 2
(unlike elements, which inherit a namespace URI).

This worries me a bit regarding how one would use the DOM Level 2 in
practice. Let's say I have the following document:

<myDocument xmlns="www.me.com" xmlns:myNS="www.me.com" >
  <myElement myAttr="1"/>
  <myElement myNS:myAttr="1"/>

Using the DOM Level 2, how can I elegantly get the value of the myElement
"a" attribute? I can't use myElement.getAttributeNS(null, "myAttr"), because
that would work for the first nested element, not for the second. I can't
use myElement.getAttributeNS("www.me.com", "myAttr"), because that would
work for the second element, and not the first. I would instead have to use
Java code something like the following *every* time I want to get an
attribute using the DOM Level 2:

public Attr findAttributeNS(Element element, String namespaceURI, String
  Attr attr=element.getAttributeNS(namespaceURI, localName);
      attr=element.getAttributeNS(null, localName);
  return attr;

This to me seems very inelegant and inefficient. Is this how it's supposed
to work?

Received on Friday, 22 December 2000 10:02:07 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:07 UTC