Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {

    public static final Node getSubNodeById(Node n, String id) {
        int i;
        NodeList children;
        Node childnode;

        if (n == null) {
            return null;
        }

        children = n.getChildNodes();

        for (i = 0; i < children.getLength(); i++) {
            childnode = children.item(i);
            NamedNodeMap nnm = childnode.getAttributes();
            if (nnm != null) {
                Node attr = nnm.getNamedItem("id");
                if (attr != null && id.equals(attr.getNodeValue())) {
                    return childnode;
                }
            }

            childnode = getSubNodeById(childnode, id);
            if (childnode != null) {
                return childnode;
            }
        }
        return null;
    }
}