Java XML Element Child Append appendChild(Document doc, Element parentElement, String elementName, String elementValue)

Here you can find the source of appendChild(Document doc, Element parentElement, String elementName, String elementValue)

Description

Add a child element to a parent element

License

Open Source License

Parameter

Parameter Description
doc a parameter
parentElement a parameter
elementName a parameter
elementValue a parameter

Declaration

public static void appendChild(Document doc, Element parentElement, String elementName, String elementValue) 

Method Source Code

//package com.java2s;
/*/* w ww. j  a v a2s .c o  m*/
 *      Copyright (c) 2004-2014 Matthew Altman & Stuart Boston
 *
 *      This file is part of TheTVDB API.
 *
 *      TheTVDB API is free software: you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation, either version 3 of the License, or
 *      any later version.
 *
 *      TheTVDB API 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 General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with TheTVDB API.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import org.w3c.dom.Text;

public class Main {
    /**
     * Add a child element to a parent element
     *
     * @param doc
     * @param parentElement
     * @param elementName
     * @param elementValue
     */
    public static void appendChild(Document doc, Element parentElement, String elementName, String elementValue) {
        Element child = doc.createElement(elementName);
        Text text = doc.createTextNode(elementValue);
        child.appendChild(text);
        parentElement.appendChild(child);
    }
}

Related

  1. appendChild(Document doc, Element parentElement, String elementName, String elementValue)
  2. appendChild(Document doc, Node parentNode, String childName, String childContents)
  3. appendChild(Document document, Node root, String name, String value)
  4. appendChildElement(Document doc, Element parent, Element child)
  5. appendChildElement(Element parent, Element el, String[] order)