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

StringgetPlainTextBelow(Node n)
Return the concatenation of the values of all text nodes below the given node.
if (n == null)
    return null;
Document doc = null;
if (n.getNodeType() == Node.DOCUMENT_NODE) {
    doc = (Document) n;
} else {
    doc = n.getOwnerDocument();
StringBuffer buf = new StringBuffer();
NodeIterator it = ((DocumentTraversal) doc).createNodeIterator(n, NodeFilter.SHOW_TEXT, null, true);
Text text = null;
while ((text = (Text) it.nextNode()) != null) {
    buf.append(text.getData().trim());
    buf.append(" ");
return buf.toString();
VectorgetPropertiesFromXML(Node propNode)
get Properties From XML
Vector<String> properties;
properties = new Vector<String>();
NodeList childList = propNode.getChildNodes();
for (int i = 0; i < childList.getLength(); i++) {
    Node currentNode = childList.item(i);
    if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
        String nodeName = currentNode.getLocalName();
        String namespace = currentNode.getNamespaceURI();
...
ListgetPropertiesFromXML(Node propNode)
get Properties From XML
ArrayList<String> properties;
properties = new ArrayList<String>();
NodeList childList = propNode.getChildNodes();
for (int i = 0; i < childList.getLength(); i++) {
    Node currentNode = childList.item(i);
    if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
        String nodeName = currentNode.getLocalName();
        String namespace = currentNode.getNamespaceURI();
...
PropertiesgetPropText(Node node)
get Prop Text
prop = new Properties();
setPropText(node);
return prop;
StringgetRawContent(Node n)
Get the raw text content of a node or null if there is no text
if (n == null) {
    return null;
StringBuilder b = null;
String s = null;
Node n1 = n.getFirstChild();
while (n1 != null) {
    if (n1.getNodeType() == Node.TEXT_NODE) {
...
StringgetSimpleElementText(final Node node)
get Simple Element Text
final NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
    final Node child = children.item(i);
    if (child instanceof Text) {
        return child.getNodeValue();
return null;
...
StringgetSimpleNodeValue(Node node)
get Simple Node Value
return node.getChildNodes().item(0).getNodeValue();
StringgetSingleNodeTextContent(Node node, String path)
get Single Node Text Content
List nodeList = getNodes(node, path);
if ((nodeList.size() > 0) && (nodeList.get(0) != null)
        && (((Node) nodeList.get(0)).getTextContent().length() > 0)) {
    return ((Node) nodeList.get(0)).getTextContent();
return null;
StringgetStrElementValue(Node node)
get Str Element Value
Node tnode = node.getFirstChild();
if (null != tnode) {
    return tnode.getNodeValue();
} else {
    return "";
StringgetString(final Node node, final String default_value)
get String
if (node != null) {
    Node text_node = node.getFirstChild();
    if (text_node == null)
        return default_value;
    return text_node.getNodeValue();
return default_value;