Here you can find the source of getOrCreateElement(Document doc, Element manifestElement, String elementName)
public static Element getOrCreateElement(Document doc, Element manifestElement, String elementName)
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { public static Element getOrCreateElement(Document doc, Element manifestElement, String elementName) { NodeList nodeList = manifestElement .getElementsByTagName(elementName); Element element = null;/* w w w.j a v a 2s . com*/ if (nodeList.getLength() == 0) { element = doc.createElement(elementName); manifestElement.appendChild(element); } else { element = (Element) nodeList.item(0); } return element; } }