Java XML Element Namespace resolveNamespacePrefix(String prefix, Element element)

Here you can find the source of resolveNamespacePrefix(String prefix, Element element)

Description

resolve Namespace Prefix

License

Open Source License

Declaration

public static String resolveNamespacePrefix(String prefix, Element element) 

Method Source Code

//package com.java2s;
/**//from ww w  . j a  v  a2  s .co m
 * This file belongs to the BPELUnit utility and Eclipse plugin set. See enclosed
 * license file for more information.
 */

import org.w3c.dom.Element;

public class Main {
    public static String resolveNamespacePrefix(String prefix, Element element) {
        String namespace = null;

        if ("".equals(prefix)) {
            namespace = element.getAttribute("xmlns");
        } else {
            namespace = element.getAttribute("xmlns:" + prefix);
        }
        if (namespace != null && !"".equals(namespace)) {
            return namespace;
        }

        if (element.getParentNode() instanceof Element) {
            return resolveNamespacePrefix(prefix, (Element) element.getParentNode());
        } else {
            throw new RuntimeException("Cannot resolve prefix " + prefix);
        }
    }
}

Related

  1. getNamespaceURI(Element element, String prefix)
  2. getNamespaceUriDeclaration(Element ele)
  3. getRequiredNamespaceDeclaration(String localName, Element element)
  4. isAppropriateElement(final Node iNode, final String iNodeName, final String iNamespace)
  5. isSameElement(final String namespace, final String localName, final XMLStreamReader reader)
  6. writeEndElement(XMLStreamWriter out, String prefix, String namespaceURI)
  7. writeStartElement(XMLStreamWriter writer, String prefix, String namespaceURI, String nodeName)