Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.Element;

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

public class Main {
    public static Element getChildElementByTagNameNS(Element parent, String tagName, String nsName) {
        NodeList nl = parent.getChildNodes();
        int size = nl.getLength();
        for (int i = 0; i < size; i++) {
            Node node = nl.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                if (tagName.equals(node.getLocalName())) {
                    String ns = node.getNamespaceURI();
                    if (ns != null && ns.equals(nsName)) {
                        return (Element) node;
                    }
                }
            }
        }

        return null;
    }
}