get XML Tag Value String - Java XML

Java examples for XML:XML Element Value

Description

get XML Tag Value String

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 getTagValueString(String sTag, Element eElement) {
        NodeList nlList = eElement.getElementsByTagName(sTag).item(0)
                .getChildNodes();// w  w  w. j  a  va2s  .  c  o  m
        Node nValue = (Node) nlList.item(0);
        String value = "0";
        try {
            value = nValue.getNodeValue();
        } catch (Exception ex1) {
            System.out
                    .println("Exception at: com.alliancerational.parser.DocUtils(13): "
                            + ex1);
        }
        return value;
    }
}

Related Tutorials