Here you can find the source of appendStringElement(Element parentElement, String nodeName, String nodeValue)
public static void appendStringElement(Element parentElement, String nodeName, String nodeValue)
//package com.java2s; /**//from w w w . j a v a 2s. c om * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation. * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * Copyright 2011 GrossCommerce */ import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { public static void appendStringElement(Element parentElement, String nodeName, String nodeValue) { // check for exists Element elem = selectSingleElement(parentElement, nodeName); if (elem == null) { elem = parentElement.getOwnerDocument().createElement(nodeName); parentElement.appendChild(elem); } elem.setTextContent(nodeValue); } public static Element selectSingleElement(Element parent, String elementName) { NodeList list = parent.getElementsByTagName(elementName); if (list.getLength() > 0) { return (Element) list.item(0); } return null; } }