Java XML Node Text Value getFirstLevelTextContent(Node node)

Here you can find the source of getFirstLevelTextContent(Node node)

Description

get First Level Text Content

License

Apache License

Declaration

public static String getFirstLevelTextContent(Node node) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static String getFirstLevelTextContent(Node node) {
        NodeList list = node.getChildNodes();
        StringBuilder textContent = new StringBuilder();
        for (int i = 0; i < list.getLength(); ++i) {
            Node child = list.item(i);
            if (child.getNodeType() == Node.TEXT_NODE)
                textContent.append(child.getTextContent());
        }//from w  ww .j ava2  s  .c  om
        return textContent.toString().trim();
    }
}

Related

  1. getDescendentText(Node node, String name)
  2. getDirectText(org.w3c.dom.Element node)
  3. getElementText(Node elem)
  4. getFirstExtensionNode(Node extensionsNode)
  5. getFirstExtensionNodeFromWorkingSet(Node extensionsNode, String workingSetName)
  6. getFirstSubElementsInnerText(Node element, String subElementName)
  7. getInnerXmlText(Node xmlNode)
  8. getNamedItemText(NamedNodeMap map, String name)
  9. getNamespaceURIFromPrefix(Node context, String prefix)