Mega Code Archive

 
Categories / Java / XML
 

Set or replace the text value

import org.w3c.dom.Node; /**  *    *  * @author Costin Manolache  */ public class Main {   /** Set or replace the text value     */    public static void setText(Node node, String val) {       Node chld=DomUtil.getChild(node, Node.TEXT_NODE);       if( chld == null ) {           Node textN=node.getOwnerDocument().createTextNode(val);           node.appendChild(textN);           return;       }       // change the value       chld.setNodeValue(val);              } }