Java XML Element Get getElementNS(Element el, String nsuri, String name)

Here you can find the source of getElementNS(Element el, String nsuri, String name)

Description

get Element NS

License

Open Source License

Declaration

public static Element getElementNS(Element el, String nsuri, String name) 

Method Source Code

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

import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Main {

    public static Element getElementNS(Element el, String nsuri, String name) {
        Node node = el.getFirstChild();
        while (node != null) {
            if (matchNS(node, nsuri, name)) {
                return (Element) node;
            }//from  www  . ja va  2  s.  c o m
            node = node.getNextSibling();
        }
        return null;
    }

    public static boolean matchNS(Node node, String nsuri, String name) {
        if (nsuri == null) {
            return node.getNamespaceURI() == null && node.getLocalName().equals(name);
        } else {
            return nsuri.equals(node.getNamespaceURI()) && node.getLocalName().equals(name);
        }
    }
}

Related

  1. getElementName(Field field)
  2. getElementName(Object obj)
  3. getElementNameSansNamespace(Element element)
  4. getElementNamespaces(Element element, Set namespaces)
  5. getElementNamespaceURI(Element element)
  6. getElementNS(Element elem, String namespaceUri, String localName)
  7. getElementNS(Element root, Set nsUris, String wantedLocalName)
  8. getElementPath(Element elem)
  9. getElementPath(Element element)