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

Here you can find the source of getNodeText(org.w3c.dom.Node node)

Description

get Node Text

License

Open Source License

Declaration

public static String getNodeText(org.w3c.dom.Node node) 

Method Source Code

//package com.java2s;

public class Main {
    public static String getNodeText(org.w3c.dom.Node node) {
        StringBuffer propertyTextBuffer = new StringBuffer();
        org.w3c.dom.NodeList children = node.getChildNodes();
        for (int j = 0; j < children.getLength(); j++) {
            org.w3c.dom.Node childNode = children.item(j);
            if (childNode instanceof org.w3c.dom.CDATASection) {
                propertyTextBuffer.append(((org.w3c.dom.CDATASection) childNode).getData());
            } else if (childNode instanceof org.w3c.dom.Text) {
                propertyTextBuffer.append(((org.w3c.dom.Text) childNode).getData().trim());
            } else if (childNode instanceof org.w3c.dom.EntityReference) {
                org.w3c.dom.NodeList grandchildren = childNode.getChildNodes();
                for (int k = 0; k < grandchildren.getLength(); k++) {
                    org.w3c.dom.Node grandchildNode = grandchildren.item(k);
                    if (grandchildNode instanceof org.w3c.dom.Text) {
                        propertyTextBuffer.append(((org.w3c.dom.Text) grandchildNode).getData());
                    }/*from w  w  w  .  j  av a 2s  .  c om*/
                }
            }
        }
        return propertyTextBuffer.toString();
    }
}

Related

  1. getNodeText(Node node)
  2. getNodeText(Node node)
  3. getNodeText(Node node)
  4. getNodeText(Node node)
  5. getNodeText(Node t)
  6. getNodeTextContent(Node node, String node_name)
  7. getNodeTexts(Node node, String... nodePath)
  8. getNodeTextValue(final Node node)
  9. getNodeTextValue(final Node node)