Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 CA.  All rights reserved.
 *
 * This source file is licensed under the terms of the Eclipse Public License 1.0
 * For the full text of the EPL please see https://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

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

public class Main {
    /**
     * Search a child node by type
     * 
     * @param parent   the parent node
     * @param nodeName   the node name
     * @param nodeType  the node type for searching
     * @return         Node with the specified name
     * @see            Node
     * @throws Exception
     */
    public static Node findChildNodeByNameAndType(Node parent, String nodeName, String nodeType) throws Exception {
        NodeList nl = parent.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            Node node = nl.item(i);
            if (node.getNodeName().equals(nodeName)) {
                String strType = node.getAttributes().getNamedItem("type").getNodeValue();
                if (strType.equals(nodeType))
                    return node;
            }
        }
        return null;
    }
}