Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    private static String getNodeValue(Node node, String fieldName) {
        Node targetNode = findNode(node, fieldName);

        return targetNode != null ? targetNode.getTextContent() : null;
    }

    private static Node findNode(Node node, String fieldName) {
        NodeList Nodes = node.getChildNodes();
        for (int i = 0; i < Nodes.getLength(); i++) {
            Node fieldNode = Nodes.item(i);
            String name = fieldNode.getNodeName();
            if (name != null && name == fieldName) {
                return fieldNode;
            }
        }
        return null;
    }
}