Here you can find the source of setElementValue(Element element, String value)
Parameter | Description |
---|---|
element | the element. |
value | the element's value. |
public static void setElementValue(Element element, String value)
//package com.java2s; /*/*from w ww . j ava 2s.c o m*/ * Copyright (c) 2012. betterFORM Project - http://www.betterform.de * Licensed under the terms of BSD License */ import org.w3c.dom.*; public class Main { /** * Appends the specified value as a text node to the element. If the * value is <code>null</code>, the element's first child node will be * removed. * * @param element the element. * @param value the element's value. */ public static void setElementValue(Element element, String value) { Node child = element.getFirstChild(); if (value != null) { if (child == null) { child = element.getOwnerDocument().createTextNode(""); element.appendChild(child); } child.setNodeValue(value); } else { if (child != null) { element.removeChild(child); } } } }