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

StringgetTexto(Node n)
Devuelve el texto de un nodo: TEXTO
NodeList nl = n.getChildNodes();
Node act = null;
for (int i = 0; i < nl.getLength(); i++) {
    act = nl.item(i);
    if (act == null)
        return null;
    if ((act.getNodeType() == Node.CDATA_SECTION_NODE) || (act.getNodeType() == Node.TEXT_NODE))
        return act.getNodeValue();
...
StringgetTextOfEl(Node e)
get Text Of El
if (e == null || e.getNodeType() != Node.ELEMENT_NODE) {
    throw new IllegalArgumentException();
Node n = e.getFirstChild();
if (n == null)
    return "";
if (n.getNodeType() == Node.TEXT_NODE) {
    String result = n.getNodeValue();
...
StringgetTextTrim(Node node)
This returns the textual content directly held under this element.
StringBuffer buf = new StringBuffer();
if (node != null) {
    NodeList children = node.getChildNodes();
    if (children != null) {
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getNodeType() == Node.CDATA_SECTION_NODE || child.getNodeType() == Node.TEXT_NODE)
                buf.append(child.getNodeValue().trim());
...
StringgetTextValue(Node node)
get Text Value
String text = node.getTextContent().trim();
text = text.replaceAll("\\n", "");
text = text.replaceAll("\\s+", " ");
return text;
StringgetTextValue(Node node)
get Text Value
Node textNode = node.getFirstChild();
if (textNode == null)
    return "";
if (textNode.getNodeType() != Node.TEXT_NODE)
    throw new SAXException("No text value found for <" + node.getNodeName() + "> node");
return textNode.getNodeValue();
StringgetTextValue(Node node)
Recursively scans all child elements, appending any text nodes.
StringBuffer text = new StringBuffer();
NodeList nodeList = node.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
    if (nodeList.item(i).getNodeType() == Node.TEXT_NODE
            || nodeList.item(i).getNodeType() == Node.CDATA_SECTION_NODE) {
        text.append(((Text) nodeList.item(i)).getData());
    } else {
        text.append(getTextValue(nodeList.item(i)));
...
StringgetTextValue(Node node)
Get the text associated with a node.
if (node != null) {
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        if (node.hasChildNodes()) {
            NodeList l = node.getChildNodes();
            int len = l.getLength();
            if (len == 1) {
                Node child = l.item(0);
                if (child.getNodeType() == Node.TEXT_NODE
...
StringgetTextValue(Node node)
Get the text node from an element node.
StringBuffer sb = new StringBuffer("");
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
    if (list.item(i).getNodeType() == Node.TEXT_NODE) {
        sb.append(list.item(i).getNodeValue());
return sb.toString();
...
StringgetTrimmedText(final Node node)
get Trimmed Text
return node.getTextContent().trim();
StringgetTrimmedTextContent(Node element)
get Trimmed Text Content
String content = element.getTextContent();
if (content == null)
    return null;
return content.trim();