get Tag Value from XML Element - Java XML

Java examples for XML:XML Element Value

Description

get Tag Value from XML Element

Demo Code


//package com.java2s;

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

public class Main {
    public static String getTagValue(String sTag, Element eElement) {
        NodeList nlList = eElement.getElementsByTagName(sTag).item(0)
                .getChildNodes();/*from ww  w.jav  a2 s  .c  o  m*/

        Node nValue = (Node) nlList.item(0);

        return nValue.getNodeValue();
    }
}

Related Tutorials