Here you can find the source of addElement(final Document document, final Element root, final String elementValue, final String elementName)
private static boolean addElement(final Document document, final Element root, final String elementValue, final String elementName)
//package com.java2s; /*//from w w w .ja va2s . com * Copyright (C) 2007 ETH Zurich * * This file is part of Fosstrak (www.fosstrak.org). * * Fosstrak is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software Foundation. * * Fosstrak is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with Fosstrak; if not, write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA */ import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { private static boolean addElement(final Document document, final Element root, final String elementValue, final String elementName) { if (isEmpty(elementValue)) { return false; } Element element = document.createElement(elementName); element.appendChild(document.createTextNode(elementValue)); root.appendChild(element); return true; } private static boolean isEmpty(String s) { return s == null || s.trim().equals(""); } }