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

voidaddElementText(Node test, List holder)
add Element Text
int Type = test.getNodeType();
switch (Type) {
case Node.CDATA_SECTION_NODE:
case Node.TEXT_NODE:
    String text = test.getNodeValue();
    if (isAlphaString(text))
        holder.add(text);
    return;
...
ElementcreateNewTextElement(Node elem, String tag, String value)
create New Text Element
Document doc = elem.getOwnerDocument();
Element res = doc.createElement(tag);
Text content = doc.createTextNode(value);
res.appendChild(content);
elem.appendChild(res);
return res;
booleanexistNode(Node node, String nodeName, String textValue)
exist Node
NodeList childs = node.getChildNodes();
for (int i = 0; i < childs.getLength(); i++) {
    if (childs.item(i).getNodeName().equals(nodeName)
            && childs.item(i).getTextContent().equals(textValue)) {
        return true;
return false;
...
StringextractNodeText(Node node)
extract Node Text
if (node.getNodeType() == Node.CDATA_SECTION_NODE)
    return node.getNodeValue();
if (node.getNodeType() == Node.TEXT_NODE)
    return node.getNodeValue();
NodeList nodelist = node.getChildNodes();
String ctext = "";
for (int i = 0; i < nodelist.getLength(); i++) {
    Node subnode = nodelist.item(i);
...
StringextractText(Node node)
extract Text
NodeList childNodes = node.getChildNodes();
if (childNodes.getLength() == 1) {
    Node child = childNodes.item(0);
    if (child.getChildNodes().getLength() == 0 && "#text".equals(child.getNodeName())) {
        return child.getNodeValue();
return null;
...
StringfindNodeText(Node node)
find Node Text
String text = null;
Node textNode = findChild(node, "#text");
if (textNode != null)
    text = textNode.getNodeValue();
return text;
Stringget_inner_text(Node node)
geinnetext
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); ++i) {
    Node child = children.item(i);
    if (child.getNodeType() == Node.TEXT_NODE)
        return child.getNodeValue();
    if (child instanceof Text)
        return ((Text) child).getData();
return null;
StringgetAppInfoText(final Node node)
Given an AppInfo Node, recurse through all the children and build a Tag / value structure for all of the Element children.
if (node == null) {
    return null;
StringBuffer str = new StringBuffer();
Node child = node.getFirstChild();
str.append("<Application Information>"); 
while (child != null) {
    short type = child.getNodeType();
...
StringgetContentsOfTextOnlyNode(Node n)
get Contents Of Text Only Node
NodeList children = n.getChildNodes();
if (children.getLength() == 0) {
    return null;
StringBuffer sb = new StringBuffer();
for (int i = 0; i < children.getLength(); i++) {
    Node node = children.item(i);
    if (node.getNodeType() == Node.TEXT_NODE) {
...
StringgetContentText(Node n)
get Content Text
if (n == null)
    return null;
if (n.getFirstChild() == null) {
    return "";
return n.getFirstChild().getNodeValue();