Java Utililty Methods XML Attribute Namespace

List of utility methods to do XML Attribute Namespace

Description

The list of methods to do XML Attribute Namespace are organized into topic(s).

Method

intcountNonNamespaceAttribures(NamedNodeMap attrs)
count Non Namespace Attribures
int n = 0;
for (int i = 0; i < attrs.getLength(); i++) {
    Attr attr = (Attr) attrs.item(i);
    if (!attr.getName().startsWith("xmlns")) {
        n++;
return n;
...
StringgetNamespaceDeclarationPrefix(Attr attr)
get Namespace Declaration Prefix
if (!W3C_XML_SCHEMA_XMLNS_URI.equals(attr.getNamespaceURI())) {
    throw new IllegalStateException(
            "Attempt to get prefix from a attribute that is not a namespace declaration, it has namespace "
                    + attr.getNamespaceURI());
String attrName = attr.getName();
if (attrName.startsWith("xmlns:")) {
    return attrName.substring(6);
...
booleanisNamespaceDef(Attr attr)
Check if the attribute node is a namespace definition.
String prefix = attr.getPrefix();
return (prefix != null && prefix.equals(XMLConstants.XMLNS_ATTRIBUTE))
        || attr.getNodeName().equals(XMLConstants.XMLNS_ATTRIBUTE);
booleanisNamespaceDefinition(Attr attr)
is Namespace Definition
if (W3C_XML_SCHEMA_XMLNS_URI.equals(attr.getNamespaceURI())) {
    return true;
if (attr.getName().startsWith("xmlns:") || "xmlns".equals(attr.getName())) {
    return true;
return false;
booleanisNoNamespaceAttribute(final XMLStreamReader reader, final int index)
is No Namespace Attribute
String namespace = reader.getAttributeNamespace(index);
return namespace == null || XMLConstants.NULL_NS_URI.equals(namespace);
StringsearchParentNamespaces(Node xml, String attribute)
Traverses up the XML Document tree looking for XML an namespace declaration that matches the given attribute.
Node next = xml;
String uri = null;
while (next != null && (uri == null || uri.length() == 0)) {
    if (next.getNodeType() == Node.ELEMENT_NODE)
        uri = ((Element) next).getAttribute(attribute);
    next = next.getParentNode();
if (uri != null && uri.length() == 0)
...