Here you can find the source of setElementValue(Element element, String val)
Parameter | Description |
---|---|
element | a parameter |
val | a parameter |
public static void setElementValue(Element element, String val)
//package com.java2s; //License from project: Apache License import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/*from w w w .j ava2 s. com*/ * Set the value of element * * @param element * @param val */ public static void setElementValue(Element element, String val) { Node node = element.getOwnerDocument().createTextNode(val); NodeList nl = element.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node nd = nl.item(i); if (nd.getNodeType() == Node.TEXT_NODE) { nd.setNodeValue(val); return; } } element.appendChild(node); } }