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[] getSubChildElement(Element ele, String tagname) {
        int p0 = tagname.indexOf(':');
        if (p0 >= 0)
            tagname = tagname.substring(p0 + 1);

        return getSubChildElement(ele, new String[] { tagname });
    }

    public static Element[] getSubChildElement(Element ele, String[] tagnames) {
        if (ele == null) {
            return null;
        }

        List<Element> v = new ArrayList<Element>();

        NodeList tmpnl = ele.getChildNodes();

        Node tmpn = null;

        int k;
        for (k = 0; k < tmpnl.getLength(); k++) {
            tmpn = tmpnl.item(k);

            if (tmpn.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }

            Element eee = (Element) tmpn;
            String noden = eee.getNodeName();
            int p = noden.indexOf(':');
            if (p >= 0)
                noden = noden.substring(p + 1);

            for (int i = 0; i < tagnames.length; i++) {
                if (tagnames[i].equals(noden) || tagnames[i].equals("*")) {
                    v.add(eee);
                    break;
                }
            }
        }

        Element[] rets = new Element[v.size()];
        v.toArray(rets);
        return rets;
    }
}