Java XML Child Element Create addElement(final Document document, final Element root, final String elementValue, final String elementName)

Here you can find the source of addElement(final Document document, final Element root, final String elementValue, final String elementName)

Description

add Element

License

Open Source License

Declaration

private static boolean addElement(final Document document, final Element root, final String elementValue,
            final String elementName) 

Method Source Code

//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("");
    }
}

Related

  1. addElement(Document document, Element father, String name, String attOneName, String attOneValue, String attTwoName, String attTwoValue)
  2. addElement(Document document, Element parentElement, String elementName, String elementValue)
  3. addElement(final Document doc, final Node parent, final String name)
  4. addElement(final Document document, final Element parentDom, final String namespace, final String name)
  5. addElement(final Document document, final Element parentDom, final String namespace, final String name)
  6. addElement(final Document dom, final Element el, final String name, final String value)
  7. addElementAndSetContent(Document doc, String name, Element parent, String text)
  8. addElementChildToElement(Document doc, Element parent, String elementName)
  9. addElementWithText(Document document, Element parentElement, String newElementName, String textString)