This is the xml:
<xml xmlns:log="http://sample.com">
<test log:writer="someWriter" />
</xml>
I am trying to get the attribute value of “log:writer” using the following line of code:
currentNode.getAttributes().getNamedItemNS("log", "writer")
I tried also to place the xmlns:log=”http://sample.com” declaration on the “test” node, but I receive always a NullPointerException. The DocumentBuilderFactory used for the Document has also the setNamespaceAware enabled. Any hint?
getNamedItemNS takes the namespaceURI as its first parameter (i.e.
http://sample.com), not the prefix (log).Edit:
Here’s a test case in full. This prints out “Attribute value is someWriter”. Tested using Xerces as the XML library. Does this work for you?