public String lookupNamespaceURI(String specifiedPrefix) {
        short type = this.getNodeType();
        switch (type) {
        case Node.ELEMENT_NODE : {

                String namespace = this.getNamespaceURI();
                String prefix = this.getPrefix();
                if (namespace !=null) {
                    // REVISIT: is it possible that prefix is empty string?
                    if (specifiedPrefix== null && prefix==specifiedPrefix) {
                        // looking for default namespace
                        return namespace;
                    } else if (prefix != null && prefix.equals(specifiedPrefix)) {
                        // non default namespace
                        return namespace;
                    }
                }
                if (this.hasAttributes()) {
                    NamedNodeMap map = this.getAttributes();
                    int length = map.getLength();
                    for (int i=0;i<length;i++) {
                        Node attr = map.item(i);
                        String attrPrefix = attr.getPrefix();
                        String value = attr.getNodeValue();
                        namespace = attr.getNamespaceURI();
                        if (namespace !=null && namespace.equals("http://www.w3.org/2000/xmlns/")) {
                            // at this point we are dealing with DOM Level 2 nodes only
                            if (specifiedPrefix == null &&
                                attr.getNodeName().equals("xmlns")) {
                                // default namespace
                                return value;
                            } else if (attrPrefix !=null &&
                                       attrPrefix.equals("xmlns") &&
                                       attr.getLocalName().equals(specifiedPrefix)) {
                 // non default namespace
                                return value;
                            }
                        }
                    }
                }
		/*
                NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
                if (ancestor != null) {
                    return ancestor.lookupNamespaceURI(specifiedPrefix);
                }
		*/

                return null;


            }
/*
        case Node.DOCUMENT_NODE : {
                return((NodeImpl)((Document)this).getDocumentElement()).lookupNamespaceURI(specifiedPrefix) ;
            }
*/
        case Node.ENTITY_NODE :
        case Node.NOTATION_NODE:
        case Node.DOCUMENT_FRAGMENT_NODE:
        case Node.DOCUMENT_TYPE_NODE:
            // type is unknown
            return null;
        case Node.ATTRIBUTE_NODE:{
                if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) {
                    return getOwnerElement().lookupNamespaceURI(specifiedPrefix);

                }
                return null;
            }
        default:{
	   /*
                NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
                if (ancestor != null) {
                    return ancestor.lookupNamespaceURI(specifiedPrefix);
                }
             */
                return null;
            }

        }
    }
public String lookupNamespaceURI ( String specifiedPrefix ) { short type = this . getNodeType ( ) ; switch ( type ) { case Node . ELEMENT_NODE : { String namespace = this . getNamespaceURI ( ) ; String prefix = this . getPrefix ( ) ; if ( namespace != null ) { if ( specifiedPrefix == null && prefix == specifiedPrefix ) { return namespace ; } else if ( prefix != null && prefix . equals ( specifiedPrefix ) ) { return namespace ; } } if ( this . hasAttributes ( ) ) { NamedNodeMap map = this . getAttributes ( ) ; int length = map . getLength ( ) ; for ( int i = 0 ; i < length ; i ++ ) { Node attr = map . item ( i ) ; String attrPrefix = attr . getPrefix ( ) ; String value = attr . getNodeValue ( ) ; namespace = attr . getNamespaceURI ( ) ; if ( namespace != null && namespace . equals ( "http://www.w3.org/2000/xmlns/" ) ) { if ( specifiedPrefix == null && attr . getNodeName ( ) . equals ( "xmlns" ) ) { return value ; } else if ( attrPrefix != null && attrPrefix . equals ( "xmlns" ) && attr . getLocalName ( ) . equals ( specifiedPrefix ) ) { return value ; } } } } return null ; } case Node . ENTITY_NODE : case Node . NOTATION_NODE : case Node . DOCUMENT_FRAGMENT_NODE : case Node . DOCUMENT_TYPE_NODE : return null ; case Node . ATTRIBUTE_NODE : { if ( this . getOwnerElement ( ) . getNodeType ( ) == Node . ELEMENT_NODE ) { return getOwnerElement ( ) . lookupNamespaceURI ( specifiedPrefix ) ; } return null ; } default : { return null ; } } }
DOM Level 3 - Experimental:
Look up the namespace URI associated to the given prefix, starting from this node.
Use lookupNamespaceURI(null) to lookup the default namespace

@param namespaceURI
@return th URI for the namespace
@since DOM Level 3