Java XML Node Text Value getTextContent(final Node node, final String defaultValue)

Here you can find the source of getTextContent(final Node node, final String defaultValue)

Description

Returns the text content of the given Node , null safe.

License

Open Source License

Parameter

Parameter Description
node can be <code>null</code>
defaultValue the value to return if the node is <code>null</code>

Return

the given default value if the node is null

Declaration

public static String getTextContent(final Node node,
        final String defaultValue) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Node;

public class Main {
    /**//from   w  w w. ja  va2 s . c om
     * Returns the text content of the given {@link Node}, null safe.
     * 
     * @param node can be <code>null</code>
     * @param defaultValue the value to return if the node is <code>null</code>
     * @return the given default value if the node is <code>null</code>
     * @see Node#getTextContent()
     * @since 1.2.0
     */
    public static String getTextContent(final Node node,
            final String defaultValue) {
        if (node == null) {
            return defaultValue;
        }
        return node.getTextContent();
    }
}

Related

  1. getTextBefore(Node node)
  2. getTextBetween(Node node1, Node node2)
  3. getTextBuffer(Node e, StringBuilder sb)
  4. getTextContent(final Node node)
  5. getTextContent(final Node node)
  6. getTextContent(final Node node, final StringBuffer sb)
  7. getTextContent(final Node xmlNode)
  8. getTextContent(Node baseNode)
  9. getTextContent(Node e)