getLocalName()
method in the DOMUtils
class?
Because 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
its 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 DOMUtils.getLocalName()
which will always return a correct local name.
[top] |
DOMUtils
class?
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
like Element.getAttributeNodeNS("http://www.w3.org/2000/xmlns/", "whatever")
will NOT work.
DOMUtils's (DOMMutils's) xmlns methods are implemented correctly and will always work - save your time and use them.
[top] |