Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;

import java.util.List;

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

public class Main {
    public static List<Element> getNamedChildren(Element parent, String... childElementNames) {
        return getNamedChildren(null, parent, childElementNames);
    }

    public static List<Element> getNamedChildren(String namespaceURI, Element parent, String... childElementNames) {
        List<Element> res = new ArrayList<Element>();
        if (null != parent) {
            for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
                if (child instanceof Element) {
                    for (String name : childElementNames) {
                        if ((namespaceURI != null && name.equals(child.getLocalName())
                                && namespaceURI.equals(child.getNamespaceURI()))
                                || (namespaceURI == null && name.equals(child.getNodeName()))) {
                            res.add((Element) child);
                            break;
                        }
                    }
                }
            }
        }
        return res;
    }
}