Java XML Node Text Value getDirectText(org.w3c.dom.Element node)

Here you can find the source of getDirectText(org.w3c.dom.Element node)

Description

get Direct Text

License

Open Source License

Declaration

public static String getDirectText(org.w3c.dom.Element node) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Main {
    public static String getDirectText(org.w3c.dom.Element node) {
        Node n = node.getFirstChild();
        StringBuilder b = new StringBuilder();
        while (n != null) {
            if (n.getNodeType() == Node.TEXT_NODE)
                b.append(n.getTextContent());
            n = n.getNextSibling();//from  w  ww.  j  a  v  a2  s . c  o m
        }
        return b.toString().trim();
    }

    public static Element getFirstChild(Element e) {
        if (e == null)
            return null;
        Node n = e.getFirstChild();
        while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
            n = n.getNextSibling();
        return (Element) n;
    }

    public static Element getNextSibling(Element e) {
        Node n = e.getNextSibling();
        while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
            n = n.getNextSibling();
        return (Element) n;
    }
}

Related

  1. get_inner_text(Node node)
  2. getAppInfoText(final Node node)
  3. getContentsOfTextOnlyNode(Node n)
  4. getContentText(Node n)
  5. getDescendentText(Node node, String name)
  6. getElementText(Node elem)
  7. getFirstExtensionNode(Node extensionsNode)
  8. getFirstExtensionNodeFromWorkingSet(Node extensionsNode, String workingSetName)
  9. getFirstLevelTextContent(Node node)