Namespace (final String prefix) { if (prefix == null) { return null; } if (NS_PREFIX_XML.equals(prefix)) { // Namespace "xml" is always bound. return Namespace.XML_NAMESPACE; } // Check if the prefix is the prefix for this element if (prefix.equals(getNamespacePrefix())) { return getNamespace(); } // Scan the additional namespaces if (additionalNamespaces != null) { for (final Namespace ns : additionalNamespaces) { if (prefix.equals(ns.getPrefix())) { return ns; } } } if (attributes != null) { for (final Attribute a : attributes) { if (prefix.equals(a.getNamespacePrefix())) { return a.getNamespace(); } } } // If we still don't have a match, ask the parent if (parent instanceof Element) { return ((Element)parent).getNamespace(prefix); } return null; }