Java XML Node Local Name getElementByTagNameNS(Node node, String namespaceURI, String localName)

Here you can find the source of getElementByTagNameNS(Node node, String namespaceURI, String localName)

Description

get Element By Tag Name NS

License

Open Source License

Declaration

static public Element getElementByTagNameNS(Node node, String namespaceURI, String localName) 

Method Source Code

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

import java.util.ArrayList;

import java.util.List;

import org.w3c.dom.Document;

import org.w3c.dom.NodeList;
import org.w3c.dom.Node;

import org.w3c.dom.Element;

public class Main {
    static public Element getElementByTagNameNS(Node node, String namespaceURI, String localName) {
        NodeList nl;//from  w  w  w  .j  a va 2s.  c  o m
        if (node.getNodeType() == Node.DOCUMENT_NODE) {
            nl = ((Document) node).getElementsByTagNameNS(namespaceURI, localName);
        } else if (node.getNodeType() == Node.ELEMENT_NODE) {
            nl = ((Element) node).getElementsByTagNameNS(namespaceURI, localName);
        } else {
            return null;
        }
        if (nl.getLength() > 0) {
            return (Element) nl.item(0);
        } else {
            return null;
        }
    }

    static public List<Element> getElementsByTagNameNS(Node node, String namespaceURI, String localName) {
        ArrayList<Element> list = new ArrayList<Element>();
        NodeList nl;
        if (node.getNodeType() == Node.DOCUMENT_NODE) {
            nl = ((Document) node).getElementsByTagNameNS(namespaceURI, localName);
        } else if (node.getNodeType() == Node.ELEMENT_NODE) {
            nl = ((Element) node).getElementsByTagNameNS(namespaceURI, localName);
        } else {
            return null;
        }
        for (int i = 0; i < nl.getLength(); i++) {
            list.add((Element) nl.item(i));
        }
        return list;
    }
}

Related

  1. getLocalName(final Node n)
  2. getLocalName(final Node node)
  3. getLocalName(Node el)
  4. getLocalName(Node element)