Java Utililty Methods XML Element Value

List of utility methods to do XML Element Value

Description

The list of methods to do XML Element Value are organized into topic(s).

Method

StringgetElementValue(Element elm)
get Element Value
String elementValue;
NodeList childNodes = elm.getChildNodes();
StringBuffer value = new StringBuffer();
for (int elemCount = 0; elemCount < childNodes.getLength(); elemCount++) {
    if (childNodes.item(elemCount) instanceof org.w3c.dom.Text) {
        value.append(childNodes.item(elemCount).getNodeValue());
elementValue = value.toString();
return elementValue;
StringgetElementValue(Element p_element)
get Element Value
Node n = p_element.getFirstChild();
if (n != null) {
    return n.getNodeValue();
return null;
StringgetElementValue(Element root, String elemName)
get the value of an Element in the Xml Document.
NodeList nl = root.getElementsByTagName(elemName);
if (null == nl) {
    return (null);
Node n = nl.item(0);
return (n.getFirstChild().getNodeValue().trim());
StringgetElementValue(final Element e)
Get the specified element's text value.
for (Node child = e.getFirstChild(); child != null; child = child.getNextSibling()) {
    if (!(child instanceof Text)) {
        continue;
    return child.getNodeValue();
return null;
StringgetElementValue(final Element target)
returns the text value associated with the element
final NodeList nodeList = target.getChildNodes();
if (nodeList == null) {
    return null;
for (int current = 0; current < nodeList.getLength(); current++) {
    final Node node = nodeList.item(current);
    if (node instanceof Text) {
        final Text text = (Text) node;
...