Java XML Element Set setTextContent(Element node, String text)

Here you can find the source of setTextContent(Element node, String text)

Description

This method is useful when DOM Level 3 "setTextContent" is not implemented

License

Open Source License

Declaration

public static void setTextContent(Element node, String text) 

Method Source Code

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

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    /**/* www . ja va2s  . c  o m*/
     * This method is useful when DOM Level 3 "setTextContent" is not implemented
     */
    public static void setTextContent(Element node, String text) {
        final NodeList children = node.getChildNodes();
        for (int i = (children.getLength() - 1); i > -1; i--) {
            node.removeChild(children.item(i));
        }
        node.appendChild(node.getOwnerDocument().createTextNode(text));
    }
}

Related

  1. setTextContent(Element elem, String content)
  2. setTextContent(Element elem, String value)
  3. setTextContent(Element element, String content)
  4. setTextContent(Element element, String content)
  5. setTextContent(Element element, String text)
  6. setTextContent(Element node, String text)
  7. setTextField(Element node, String subElement, String text)
  8. setTextValue(Element element, String text)
  9. setTextValue(Element element, String value)