getLocalName()method in the
Node.getLocalName() method is simply unusable.
Do you think that the function will always return a correct local name? Wrong.
It does so only for nodes created by the DOM Level 2 methods. So, if
you (or the DOM implementation, during the XML parsing) create an attribute
with null namespace, chances are that the node will have the DOM Level 1 implementation and
getLocalName() method will simply return null.
A simple example: Xerces (the one present in the JRE5) creates instances of
DeferredAttrImpl for each attribute with null namespace when
parsing a XML file. This
DeferredAttrImpl class is an implementation
of DOM Level 1 and thus its getLocalName() method always returns null.
To prevent this stupid behavior you should always use
which will always return a correct local name.
Another interesting issue. One may expect that the xmlns:whatever attribute will have
namespace equal to
http://www.w3.org/2000/xmlns/. However, xerces
will simply create an attribute with null namespace and null localname, hence something
will NOT work.
DOMUtils's (DOMMutils's) xmlns methods are implemented correctly and will always work - save your time and use them.