Java XML Element Namespace getRequiredNamespaceDeclaration(String localName, Element element)

Here you can find the source of getRequiredNamespaceDeclaration(String localName, Element element)

Description

get Required Namespace Declaration

License

Open Source License

Declaration

public static Node getRequiredNamespaceDeclaration(String localName, Element element) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.*;

public class Main {
    public static Node getRequiredNamespaceDeclaration(String localName, Element element) {
        Node node = getNamespaceDeclarationOrNull(localName, element);
        if (node == null) {
            throw new IllegalStateException(
                    String.format("Namespace declaration for prefix '%s' not found", localName));
        }/*  w w w  .  j  a v a  2  s. c  o m*/
        return node;
    }

    public static Node getNamespaceDeclarationOrNull(String localName, Element element) {
        NamedNodeMap map = element.getAttributes();
        for (int i = 0; i < map.getLength(); i++) {
            Node node = map.item(i);
            String nsUri = node.getNamespaceURI();
            if (nsUri == null) {
                continue;
            }
            if ("http://www.w3.org/2000/xmlns/".equals(nsUri) && localName.equals(node.getLocalName())) {
                return node;
            }
        }
        return null;
    }
}

Related

  1. getNamespace(Element element)
  2. getNamespaceDeclarationOrNull(String localName, Element element)
  3. getNamespaceForPrefix(String prefix, Element element)
  4. getNamespaceURI(Element element, String prefix)
  5. getNamespaceUriDeclaration(Element ele)
  6. isAppropriateElement(final Node iNode, final String iNodeName, final String iNamespace)
  7. isSameElement(final String namespace, final String localName, final XMLStreamReader reader)
  8. resolveNamespacePrefix(String prefix, Element element)
  9. writeEndElement(XMLStreamWriter out, String prefix, String namespaceURI)