get XML Element Child As String - Java XML

Java examples for XML:XML Element Child

Description

get XML Element Child As String

Demo Code


//package com.java2s;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class Main {
    public static String getChildAsString(Element e, String child) {
        NodeList nodes = e.getElementsByTagName(child);
        if (nodes.getLength() > 0) {
            Element i = (Element) nodes.item(0);
            return i.getTextContent().trim();
        } else// w w  w.j a  va2  s .  com
            return null;
    }
}

Related Tutorials