Java XML Child Element Create addChild(final Document doc, Element parent, final String childName, final String childValue)

Here you can find the source of addChild(final Document doc, Element parent, final String childName, final String childValue)

Description

add Child

License

Open Source License

Declaration

public static void addChild(final Document doc, Element parent,
            final String childName, final String childValue) 

Method Source Code

//package com.java2s;
/*/*from w  w  w. j a  va2s.c  o  m*/
 * LastPod is an application used to publish one's iPod play counts to Last.fm.
 * Copyright (C) 2007  Chris Tilden
 *
 * This program 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 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 this program; 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;
import org.w3c.dom.Text;

public class Main {
    public static void addChild(final Document doc, Element parent,
            final String childName, final String childValue) {
        Element child = doc.createElement(childName);
        Text text = doc.createTextNode(childValue);
        child.appendChild(text);
        parent.appendChild(child);
    }
}

Related

  1. addChild(Document doc, Node parent, String name)
  2. addChildElement(Document doc, Node parent, String tag)
  3. addChildElement(Document document, String elementName, Node parentNode)
  4. addChildElement(Element element, String childElementName, Document document)
  5. addChildElementNSElement(Element element, String childElementName, Document document, String nameSpaceUrl)