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 String getElementValue(Element parent, String childName, String childNamespace) {
        Element child = getChildElement(parent, childName, childNamespace);
        if (child == null)
            return null;

        return child.getTextContent();
    }

    public static Element getChildElement(Element parent, String childName, String childNamespace) {
        NodeList ns = parent.getChildNodes();
        for (int i = 0; i < ns.getLength(); i++) {
            Node n = ns.item(i);
            if (n instanceof Element) {
                Element child = (Element) n;
                if (childName.equals(child.getLocalName()) && childNamespace.equals(child.getNamespaceURI())) {
                    return child;
                }
            }
        }
        return null;
    }
}