Java Utililty Methods XML Node Text Value

List of utility methods to do XML Node Text Value

Description

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

Method

StringgetString(Node node)
get String
return node.getTextContent();
StringgetStringValue(NamedNodeMap values, String name)
get String Value
return getStringValue(values, name, null);
StringgetStringValue(Node node)
Return the String value of a Node.
String value = node.getNodeValue();
if (node.hasChildNodes()) {
    Node first = node.getFirstChild();
    if (first.getNodeType() == Node.TEXT_NODE) {
        return first.getNodeValue();
return value;
...
StringgetStringValue(Node node)
Return the String value of a Node.
String value = node.getNodeValue();
if (node.hasChildNodes()) {
    Node first = node.getFirstChild();
    if (first.getNodeType() == Node.TEXT_NODE) {
        return first.getNodeValue();
return value;
...
StringgetTagValue(Node node, String name)
get Tag Value
if (node.getNodeType() == Node.ELEMENT_NODE) {
    Element el = (Element) node;
    NodeList nodeList = el.getElementsByTagName(name);
    if (nodeList.getLength() > 0) {
        el = (Element) nodeList.item(0);
        nodeList = el.getChildNodes();
        if (nodeList.getLength() > 0) {
            return ((Node) nodeList.item(0)).getNodeValue();
...
StringgetTagValueWithoutNamespace(Node n)
Gets the tag value without namespace.
if (n != null) {
    String tag = n.getNodeName();
    return tag.substring(tag.indexOf(":") + 1, tag.length());
return null;
StringgetText(final Node node)
get Text
StringBuilder sb = new StringBuilder();
getText(node, sb);
return sb.toString();
StringgetText(final Node xmlNode)
Retrieves contents of first Text Node defined within an XML Node
return xmlNode == null ? null : xmlFindTextNode(xmlNode);
StringgetText(Node elem)
get Text
if (elem.getNodeType() == Element.TEXT_NODE)
    return elem.getTextContent();
else if (elem.hasChildNodes())
    return elem.getFirstChild().getTextContent();
return "";
StringgetText(Node elem, StringBuilder buffer)
get Text
if (elem.getNodeType() != Node.CDATA_SECTION_NODE) {
    NodeList childs = elem.getChildNodes();
    for (int i = 0; i < childs.getLength(); i++) {
        Node child = childs.item(i);
        short childType = child.getNodeType();
        if (childType != Node.COMMENT_NODE && childType != Node.PROCESSING_INSTRUCTION_NODE) {
            getText(child, buffer);
} else {
    buffer.append(elem.getNodeValue());
return buffer.toString();