Thursday 4 August 2011

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);
      ifchld == null ) {
          Node textN=node.getOwnerDocument().createTextNode(val);
          node.appendChild(textN);
          return;
      }
      // change the value
      chld.setNodeValue(val);           
  }

}

   
  

No comments:

Post a Comment