Example usage for org.w3c.dom Node CDATA_SECTION_NODE

List of usage examples for org.w3c.dom Node CDATA_SECTION_NODE

Introduction

In this page you can find the example usage for org.w3c.dom Node CDATA_SECTION_NODE.

Prototype

short CDATA_SECTION_NODE

To view the source code for org.w3c.dom Node CDATA_SECTION_NODE.

Click Source Link

Document

The node is a CDATASection.

Usage

From source file:architecture.ee.jdbc.sqlquery.builder.xml.XmlStatementBuilder.java

private List<SqlNode> parseDynamicTags(XNode node) {
    List<SqlNode> contents = new ArrayList<SqlNode>();
    NodeList children = node.getNode().getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        XNode child = node.newXNode(children.item(i));
        String nodeName = child.getNode().getNodeName();
        if (child.getNode().getNodeType() == Node.CDATA_SECTION_NODE
                || child.getNode().getNodeType() == Node.TEXT_NODE) {
            String data = child.getStringBody("");
            contents.add(new TextSqlNode(data));
        } else {//from w w  w  .  j av a  2 s.c  o m
            if ("dynamic".equals(nodeName)) {
                String data = child.getStringBody("");
                contents.add(new DynamicSqlNode(data));
            }
        }
    }
    return contents;
}

From source file:cc.siara.csv_ml.ParsedObject.java

/**
 * Performas any pending activity against an element to finalize it. In this
 * case, it adds any pending attributes needing namespace mapping.
 * /*from   w w w. j  a  v a  2 s .c  om*/
 * Also if the node has a namespace attached, it recreates the node with
 * specific URI.
 */
public void finalizeElement() {
    // Add all remaining attributes
    for (String col_name : pendingAttributes.keySet()) {
        String value = pendingAttributes.get(col_name);
        int cIdx = col_name.indexOf(':');
        String ns = col_name.substring(0, cIdx);
        String nsURI = nsMap.get(ns);
        if (nsURI == null)
            nsURI = generalNSURI;
        Attr attr = doc.createAttributeNS(nsURI, col_name.substring(cIdx + 1));
        attr.setPrefix(ns);
        attr.setValue(value);
        ((Element) cur_element).setAttributeNodeNS(attr);
    }
    // If the element had a namespace prefix, it has to be recreated.
    if (!currentElementNS.equals("") && !doc.getDocumentElement().equals(cur_element)) {
        Node parent = cur_element.getParentNode();
        Element cur_ele = (Element) parent.removeChild(cur_element);
        String node_name = cur_ele.getNodeName();
        String nsURI = nsMap.get(currentElementNS);
        if (nsURI == null)
            nsURI = generalNSURI;
        Element new_node = doc.createElementNS(nsURI, currentElementNS + ":" + node_name);
        parent.appendChild(new_node);
        // Add all attributes
        NamedNodeMap attrs = cur_ele.getAttributes();
        while (attrs.getLength() > 0) {
            Attr attr = (Attr) attrs.item(0);
            cur_ele.removeAttributeNode(attr);
            nsURI = attr.getNamespaceURI();
            new_node.setAttributeNodeNS(attr);
        }
        // Add all CData sections
        NodeList childNodes = cur_ele.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node node = childNodes.item(i);
            if (node.getNodeType() == Node.CDATA_SECTION_NODE)
                new_node.appendChild(node);
        }
        cur_element = new_node;
    }
    pendingAttributes = new Hashtable<String, String>();
}

From source file:it.delli.mwebc.servlet.MWebCRenderer.java

public static void buildLayout(Element elem, Widget parent, Page page) throws Exception {
    Widget widget = null;//from   www  . ja  va  2s . c  o m
    if (elem.getNodeType() == Node.ELEMENT_NODE && elem.getNodeName().equals("Page")) {
        for (int j = 0; j < elem.getAttributes().getLength(); j++) {
            Node attribute = elem.getAttributes().item(j);
            if (!attribute.getNodeName().equals("id")) {
                if (attribute.getNodeName().equals("eventListener")) {
                    log.debug("Setting PageEventListener");
                    try {
                        page.setEventListener(
                                (PageEventListener) Class.forName(attribute.getNodeValue()).newInstance());
                    } catch (Exception e) {
                        log.error("Exception in setting PageEventListener");
                    }
                }
            }
        }
        if (page.getEventListener() == null) {
            log.debug("Setting default PageEventListener");
            page.setEventListener(new PageEventListener() {

                @Override
                public void onLoad(Event event) {
                }

                @Override
                public void onInit(Event event) {
                }

            });
        }
        for (int i = 0; i < elem.getChildNodes().getLength(); i++) {
            Node node = elem.getChildNodes().item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                buildLayout((Element) node, widget, page);
            }
        }
    } else if (elem.getNodeType() == Node.ELEMENT_NODE && elem.getNodeName().equals("PageFragment")) {
        for (int i = 0; i < elem.getChildNodes().getLength(); i++) {
            Node node = elem.getChildNodes().item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                buildLayout((Element) node, parent, page);
            }
        }
    } else {
        Class<?> widgetClass = page.getApplication().getWidgetClass(elem.getNodeName());
        if (widgetClass == null) {
            log.fatal("Exception in getting widget class for widget " + elem.getNodeName());
            throw new Exception();
        } else if (widgetClass.getName().equals("com.dodifferent.applications.commander.widget.DataListItem")) {
            System.out.println();
        }
        CastHelper castHelper = page.getApplication().getCastHelper(widgetClass);

        String id = null;
        for (int j = 0; j < elem.getAttributes().getLength(); j++) {
            Node attribute = elem.getAttributes().item(j);
            if (attribute.getNodeName().equals("id")) {
                id = attribute.getNodeValue();
                break;
            }
        }

        HashMap<String, Object> initParams = new HashMap<String, Object>();
        for (int j = 0; j < elem.getAttributes().getLength(); j++) {
            Node attributeNode = elem.getAttributes().item(j);
            if (!attributeNode.getNodeName().equals("id") && !attributeNode.getNodeName().startsWith("on")) {
                Field fieldAttribute = ReflectionUtils.getAnnotatedField(widgetClass,
                        attributeNode.getNodeName(), WidgetAttribute.class);
                if (fieldAttribute != null) {
                    fieldAttribute.setAccessible(true);
                    Class<?> propertyType = fieldAttribute.getType();
                    //                  Type[] genericTypes = ((ParameterizedType)fieldAttribute.getGenericType()).getActualTypeArguments();
                    initParams.put(attributeNode.getNodeName(),
                            castHelper.toType(attributeNode.getNodeValue(), propertyType));
                } else {
                    log.warn("Warning in updating server widgets attribute. The attribute '"
                            + attributeNode.getNodeName() + "' doesn't exist for widget "
                            + widgetClass.getName());
                }
            }
        }

        try {
            if (id != null && initParams.keySet().size() == 0) {
                Class[] constructorParams = { Page.class, String.class };
                Constructor widgetConstructor = page.getApplication().getWidgetClass(elem.getNodeName())
                        .getConstructor(constructorParams);
                widget = (Widget) widgetConstructor.newInstance(page, id);
            } else if (id != null && initParams.keySet().size() > 0) {
                Class[] constructorParams = { Page.class, String.class, Map.class };
                Constructor widgetConstructor = page.getApplication().getWidgetClass(elem.getNodeName())
                        .getConstructor(constructorParams);
                widget = (Widget) widgetConstructor.newInstance(page, id, initParams);
            } else if (id == null && initParams.keySet().size() == 0) {
                Class[] constructorParams = { Page.class };
                Constructor widgetConstructor = page.getApplication().getWidgetClass(elem.getNodeName())
                        .getConstructor(constructorParams);
                widget = (Widget) widgetConstructor.newInstance(page);
            } else if (id == null && initParams.keySet().size() > 0) {
                Class[] constructorParams = { Page.class, Map.class };
                Constructor widgetConstructor = page.getApplication().getWidgetClass(elem.getNodeName())
                        .getConstructor(constructorParams);
                widget = (Widget) widgetConstructor.newInstance(page, initParams);
            }
        } catch (Exception e) {
            log.error("Exception in constructing widget " + widget.getClass().getName() + " (" + widget.getId()
                    + ")", e);
        }

        if (widget != null) {
            for (int j = 0; j < elem.getAttributes().getLength(); j++) {
                Node attributeNode = elem.getAttributes().item(j);
                if (!attributeNode.getNodeName().equals("id") && attributeNode.getNodeName().startsWith("on")) {
                    String event = attributeNode.getNodeName();
                    try {
                        widget.addEventListener(event, page.getEventListener(), attributeNode.getNodeValue());
                        //                     Method eventMethod = widget.getClass().getMethod("addEventListener", String.class, EventListener.class, String.class);
                        //                     eventMethod.invoke(widget, event, page.getEventListener(), attributeNode.getNodeValue());
                    } catch (Exception e) {
                        log.warn("Warning in registering EventListener for widget "
                                + widget.getClass().getName() + " (" + widget.getId() + ")", e);
                    }
                }
            }
            for (int i = 0; i < elem.getChildNodes().getLength(); i++) {
                Node node = elem.getChildNodes().item(i);
                if (node.getNodeType() == Node.CDATA_SECTION_NODE || node.getNodeType() == Node.TEXT_NODE) {
                    try {
                        String content = node.getNodeValue().replace("\t", "").replace("\n", "").replace("\"",
                                "\\\"");
                        if (!content.equals("")) {
                            //                        Method attributeMethod = widget.getClass().getMethod("addTextContent", String.class);
                            //                        attributeMethod.invoke(widget, content);
                            widget.addTextContent(content);
                        }
                    } catch (Exception e) {
                        log.warn("Warning in setting content for widget " + widget.getClass().getName() + " ("
                                + widget.getId() + ")", e);
                    }
                } else if (node.getNodeType() == Node.ELEMENT_NODE) {
                    buildLayout((Element) node, widget, page);
                }
            }
            widget.setParent(parent);
        }
    }
}

From source file:Main.java

private static void renderNode(StringBuffer sb, Node node, String margin, String indent, String lab, String rab,
        String nl) {/* w w w  .  ja v a  2  s  . c o m*/
    if (node == null) {
        sb.append("null");
        return;
    }
    switch (node.getNodeType()) {

    case Node.DOCUMENT_NODE:
        //sb.append(margin + lab +"?xml version=\"1.0\" encoding=\"UTF-8\"?" + rab + nl);
        Node root = ((Document) node).getDocumentElement();
        renderNode(sb, root, margin, indent, lab, rab, nl);
        break;

    case Node.ELEMENT_NODE:
        String name = getNodeNameWithNamespace(node);
        NodeList children = node.getChildNodes();
        int nChildren = children.getLength();
        NamedNodeMap attributes = node.getAttributes();
        int nAttrs = attributes.getLength();

        boolean singleShortTextChild = (nAttrs == 0) && (nChildren == 1)
                && (children.item(0).getNodeType() == Node.TEXT_NODE)
                && (children.item(0).getTextContent().length() < 70)
                && (!children.item(0).getTextContent().contains("\n"));

        if (singleShortTextChild) {
            sb.append(margin + lab + name + ((nChildren == 0) ? "/" : "") + rab);
        } else if (nAttrs == 0 && !singleShortTextChild) {
            sb.append(margin + lab + name + ((nChildren == 0) ? "/" : "") + rab + nl);
        } else if (nAttrs == 1) {
            Node attr = attributes.item(0);
            String attrName = getNodeNameWithNamespace(attr);
            sb.append(margin + lab + name + " " + attrName + "=\"" + escapeChars(attr.getNodeValue()) + "\""
                    + ((nChildren == 0) ? "/" : "") + rab + nl);
        } else {
            sb.append(margin + lab + name + nl);
            for (int i = 0; i < nAttrs; i++) {
                Node attr = attributes.item(i);
                String attrName = getNodeNameWithNamespace(attr);
                sb.append(margin + indent + attrName + "=\"" + escapeChars(attr.getNodeValue()));
                if (i < nAttrs - 1)
                    sb.append("\"" + nl);
                else
                    sb.append("\"" + ((nChildren == 0) ? "/" : "") + rab + nl);
            }
        }
        if (singleShortTextChild) {
            String text = escapeChars(node.getTextContent());
            sb.append(text.trim());
            sb.append(lab + "/" + name + rab + nl);
        } else {
            for (int i = 0; i < nChildren; i++) {
                renderNode(sb, children.item(i), margin + indent, indent, lab, rab, nl);
            }
        }
        if (nChildren != 0 && !singleShortTextChild)
            sb.append(margin + lab + "/" + name + rab + nl);
        break;

    case Node.TEXT_NODE:
        String text = escapeChars(node.getNodeValue());
        String[] lines = text.split("\n");
        for (String line : lines) {
            line = line.trim();
            if (!line.equals(""))
                sb.append(margin + line + nl);
        }
        break;

    case Node.CDATA_SECTION_NODE:
        String cdataText = node.getNodeValue();
        String[] cdataLines = cdataText.split("\n");
        sb.append(margin + lab + "![CDATA[" + nl);
        for (String line : cdataLines) {
            line = line.trim();
            if (!line.equals(""))
                sb.append(margin + indent + line + nl);
        }
        sb.append(margin + "]]" + rab + nl);
        break;

    case Node.PROCESSING_INSTRUCTION_NODE:
        sb.append(margin + lab + "?" + node.getNodeName() + " " + escapeChars(node.getNodeValue()) + "?" + rab
                + nl);
        break;

    case Node.ENTITY_REFERENCE_NODE:
        sb.append("&" + node.getNodeName() + ";");
        break;

    case Node.DOCUMENT_TYPE_NODE:
        // Ignore document type nodes
        break;

    case Node.COMMENT_NODE:
        sb.append(margin + lab + "!--" + node.getNodeValue() + "--" + rab + nl);
        break;
    }
    return;
}

From source file:ValidateLicenseHeaders.java

/**
 * Get all non-comment content from the element.
 * /*from   ww w . jav  a2 s .  c om*/
 * @param element
 * @return the concatenated text/cdata content
 */
public static String getElementContent(Element element) {
    if (element == null)
        return null;

    NodeList children = element.getChildNodes();
    StringBuffer result = new StringBuffer();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child.getNodeType() == Node.TEXT_NODE || child.getNodeType() == Node.CDATA_SECTION_NODE) {
            result.append(child.getNodeValue());
        } else if (child.getNodeType() == Node.COMMENT_NODE) {
            // Ignore comment nodes
        } else {
            result.append(child.getFirstChild());
        }
    }
    return result.toString().trim();
}

From source file:com.centurylink.mdw.hub.servlet.SoapServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    CodeTimer timer = new CodeTimer("SoapServlet.doPost()", true);

    InputStream reqInputStream = request.getInputStream();
    // read the POST request contents
    String requestString = getRequestString(request);
    if (logger.isMdwDebugEnabled()) {
        logger.mdwDebug("SOAP Listener POST Request:\n" + requestString);
    }//from  www .j a  v a2  s . c  o  m

    Map<String, String> metaInfo = buildMetaInfo(request);

    String responseString = null;
    MessageFactory factory = null;
    String soapVersion = SOAPConstants.SOAP_1_1_PROTOCOL;
    try {
        SOAPMessage message = null;
        SOAPBody body = null;
        try {
            // Intuitively guess which SOAP version is needed
            // factory = getMessageFactory(requestString, true);
            soapVersion = getSoapVersion(requestString, true);
            factory = getSoapMessageFactory(soapVersion);
            reqInputStream = new ByteArrayInputStream(requestString.getBytes());

            message = factory.createMessage(null, reqInputStream);
            body = message.getSOAPBody();
        } catch (SOAPException e) {
            // Unlikely, but just in case the SOAP version guessing
            // has guessed incorrectly, this catches any SOAP exception,
            // in which case try the other version
            if (logger.isMdwDebugEnabled()) {
                logger.mdwDebug(
                        "SOAPListenerServlet failed to find correct Message Factory:" + "\n" + e.getMessage());
            }
            // Try with the other unintuitive MessageFactory
            // factory = getMessageFactory(requestString, false);
            soapVersion = getSoapVersion(requestString, false);
            factory = getSoapMessageFactory(soapVersion);
            reqInputStream = new ByteArrayInputStream(requestString.getBytes());

            message = factory.createMessage(null, reqInputStream);
            body = message.getSOAPBody();
            // Only 2 versions, so let any exceptions bubble up
        }
        Node childElem = null;
        Iterator<?> it = body.getChildElements();
        while (it.hasNext()) {
            Node node = (Node) it.next();
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                childElem = node;
                break;
            }
        }
        if (childElem == null)
            throw new SOAPException("SOAP body child element not found");

        String requestXml = null;

        boolean oldStyleRpcRequest = false;
        if (request.getServletPath().endsWith(RPC_SERVICE_PATH)
                || RPC_SERVICE_PATH.equals(request.getPathInfo())) {
            NodeList nodes = childElem.getChildNodes();
            for (int i = 0; i < nodes.getLength(); i++) {
                if (StringUtils.isNotBlank(nodes.item(i).getNodeName())
                        && nodes.item(i).getNodeName().equals("RequestDetails")) {
                    oldStyleRpcRequest = true;
                    Node requestNode = nodes.item(i).getFirstChild();
                    if (requestNode.getNodeType() == Node.CDATA_SECTION_NODE) {
                        requestXml = requestNode.getTextContent();
                    } else {
                        requestXml = DomHelper.toXml(requestNode);
                        if (requestXml.contains("&lt;"))
                            requestXml = StringEscapeUtils.unescapeXml(requestXml);
                    }
                }
            }
        } else {
            requestXml = DomHelper.toXml(childElem);
        }

        metaInfo = addSoapMetaInfo(metaInfo, message);
        ListenerHelper helper = new ListenerHelper();

        try {
            authenticate(request, metaInfo, requestXml);
            String handlerResponse = helper.processEvent(requestXml, metaInfo);

            try {
                // standard response indicates a potential problem
                MDWStatusMessageDocument responseDoc = MDWStatusMessageDocument.Factory.parse(handlerResponse,
                        Compatibility.namespaceOptions());
                MDWStatusMessage responseMsg = responseDoc.getMDWStatusMessage();
                if ("SUCCESS".equals(responseMsg.getStatusMessage()))
                    responseString = createSoapResponse(soapVersion, handlerResponse);
                else
                    responseString = createSoapFaultResponse(soapVersion,
                            String.valueOf(responseMsg.getStatusCode()), responseMsg.getStatusMessage());
            } catch (XmlException xex) {
                if (Listener.METAINFO_ERROR_RESPONSE_VALUE
                        .equalsIgnoreCase(metaInfo.get(Listener.METAINFO_ERROR_RESPONSE))) {
                    // Support for custom error response
                    responseString = handlerResponse;
                } else {
                    // not parseable as standard response doc (a good thing)
                    if (oldStyleRpcRequest) {
                        responseString = createOldStyleSoapResponse(soapVersion,
                                "<m:invokeWebServiceResponse xmlns:m=\"http://mdw.qwest.com/listener/webservice\"><Response>"
                                        + StringEscapeUtils.escapeXml(handlerResponse)
                                        + "</Response></m:invokeWebServiceResponse>");
                    } else {
                        responseString = createSoapResponse(soapVersion, handlerResponse);
                    }
                }
            }
        } catch (ServiceException ex) {
            logger.severeException(ex.getMessage(), ex);
            responseString = createSoapFaultResponse(soapVersion, String.valueOf(ex.getCode()),
                    ex.getMessage());
        }
    } catch (Exception ex) {
        logger.severeException(ex.getMessage(), ex);
        try {
            responseString = createSoapFaultResponse(soapVersion, null, ex.getMessage());
        } catch (Exception tex) {
            logger.severeException(tex.getMessage(), tex);
        }
    }

    if (logger.isMdwDebugEnabled()) {
        logger.mdwDebug("SOAP Listener Servlet POST Response:\n" + responseString);
    }

    if (metaInfo.get(Listener.METAINFO_CONTENT_TYPE) != null) {
        response.setContentType(metaInfo.get(Listener.METAINFO_CONTENT_TYPE));
    } else {
        if (soapVersion.equals(SOAPConstants.SOAP_1_1_PROTOCOL))
            response.setContentType(Listener.CONTENT_TYPE_XML);
        else
            response.setContentType("application/soap+xml");
    }

    response.getOutputStream().print(responseString);

    timer.stopAndLogTiming("");
}

From source file:com.twinsoft.convertigo.beans.core.RequestableStep.java

@Override
public void configure(Element element) throws Exception {
    super.configure(element);

    String version = element.getAttribute("version");

    if (version == null) {
        String s = XMLUtils.prettyPrintDOM(element);
        EngineException ee = new EngineException(
                "Unable to find version number for the database object \"" + getName() + "\".\nXML data: " + s);
        throw ee;
    }/*from  w w w.  ja v a  2 s. com*/

    try {
        NodeList childNodes = element.getElementsByTagName("wsdltype");
        int len = childNodes.getLength();
        if (len > 0) {
            Node childNode = childNodes.item(0);
            Node cdata = XMLUtils.findChildNode(childNode, Node.CDATA_SECTION_NODE);
            if (cdata != null) {
                wsdlType = cdata.getNodeValue();
                Engine.logBeans.trace("(RequestableStep) configure() : wsdltype has been successfully set");
            } else
                Engine.logBeans.trace("(RequestableStep) configure() : wsdltype is empty");
        }
    } catch (Exception e) {
        throw new EngineException(
                "Unable to retrieve the wsdltype for the sequence step \"" + getName() + "\".", e);
    }

    if (VersionUtils.compare(version, "4.6.0") < 0) {
        // Backup wsdlTypes to file
        try {
            backupWsdlTypes(element);
            if (!wsdlType.equals("")) {
                wsdlType = "";
                hasChanged = true;
                Engine.logBeans.warn("[RequestableStep] Successfully backup wsdlTypes for step \"" + getName()
                        + "\" (v 4.6.0)");
            } else {
                Engine.logBeans.warn("[RequestableStep] Empty wsdlTypes for step \"" + getName()
                        + "\", none backup done (v 4.6.0)");
            }
        } catch (Exception e) {
            Engine.logBeans.error(
                    "[RequestableStep] Could not backup wsdlTypes for step \"" + getName() + "\" (v 4.6.0)", e);
        }
    }
}

From source file:com.doculibre.constellio.feedprotocol.parse.xml.FeedParser.java

private List<FeedContent> parseContentElements(NodeList contentsNodeList) throws ParseFeedException {
    List<FeedContent> contents = new ArrayList<FeedContent>();
    for (int i = 0; i < contentsNodeList.getLength(); i++) {
        Element contentElement = (Element) contentsNodeList.item(i);

        String encoding = getAttrValueIfPresent(contentElement, XML_CONTENT_ENCODING);
        NodeList nodeList = contentElement.getChildNodes();
        //System.out.println("Length: " + nodeList.getLength());
        if (nodeList.getLength() == 1) {
            Node childNode = nodeList.item(0);
            if (childNode.getNodeType() == Node.TEXT_NODE
                    || childNode.getNodeType() == Node.CDATA_SECTION_NODE) {
                String value = contentElement.getChildNodes().item(0).getNodeValue();
                //System.out.println("Value: " + value);
                throw new NotImplementedException("Feed must be transfed to file");
                //FeedContent content = new FeedContentImpl(value, encoding);
                //contents.add(content);
            }//from ww w  .j  ava 2s  . c  o m
        }
    }
    return contents;
}

From source file:com.impetus.kundera.ejb.PersistenceXmlLoader.java

/**
 * Get the content of the given element.
 * /*from  w  ww.ja va  2  s .c  o  m*/
 * @param element
 *            The element to get the content for.
 * @param defaultStr
 *            The default to return when there is no content.
 * @return The content of the element or the default.
 * @throws Exception
 *             the exception
 */
private static String getElementContent(Element element, String defaultStr) throws Exception {
    if (element == null) {
        return defaultStr;
    }

    NodeList children = element.getChildNodes();
    StringBuilder result = new StringBuilder("");
    for (int i = 0; i < children.getLength(); i++) {
        if (children.item(i).getNodeType() == Node.TEXT_NODE
                || children.item(i).getNodeType() == Node.CDATA_SECTION_NODE) {
            result.append(children.item(i).getNodeValue());
        }
    }
    return result.toString().trim();
}

From source file:DOMProcessor.java

/** Searches for a given node and returns text associated with
  * it. This version does not recurse to the node's children.
  * @param node Node to search./*from   www . j  a  va 2s. c  om*/
  * @return Text associated with the node, or null if none found.
  */
public String getNodeText(Node node) {
    // Look for text in child (text stored in its own node).
    NodeList children = node.getChildNodes();

    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)) {
            return (child.getNodeValue());
        }
    }

    // If we get this far, no text was found.
    return null;
}