Here you can find the source of findElementElseCreateAndSet(Document document, Element parent, String child, boolean value)
public static Element findElementElseCreateAndSet(Document document, Element parent, String child, boolean value)
//package com.java2s; //License from project: Apache License import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { public static Element findElementElseCreateAndSet(Document document, Element parent, String child, String value) {/*ww w . j a v a2s .c o m*/ Element ret = null; NodeList nl = parent.getElementsByTagName(child); if (nl.getLength() == 0) { parent.appendChild(document.createElement(child)); ret = (Element) parent.getElementsByTagName(child).item(0); ret.appendChild(document.createTextNode(value)); } return ret; } public static Element findElementElseCreateAndSet(Document document, Element parent, String child, boolean value) { return findElementElseCreateAndSet(document, parent, child, value + ""); } }