Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Element;

import org.w3c.dom.Node;

public class Main {
    public static String getFirstMatchedValueByChildTagName(Node parent, String name) {
        //List<Element> nodeList = new ArrayList<Element>();
        for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
            //System.out.println(child.getNodeName());
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                if (child.getNodeName().indexOf(name) != -1) {
                    return child.getTextContent();
                } else {
                    String value = getFirstMatchedValueByChildTagName((Element) child, name);
                    if (value != null) {
                        return value;
                    }
                }
            }
        }
        return null;
    }
}