Java XML Duration Add appendElement(Node parent, String tagName)

Here you can find the source of appendElement(Node parent, String tagName)

Description

Appends a child element with the given tag name to the specified parent node.

License

Open Source License

Parameter

Parameter Description
parent the parent node
tagName the tag name

Return

the new element with the given tag name that is a child of the parent node

Declaration

public static Element appendElement(Node parent, String tagName) 

Method Source Code


//package com.java2s;
/*   ********************************************************************** **
**   Copyright (c) 2006-2007 Christopher J. Stehno (chris@stehno.com)       **
**   http://www.stehno.com                                                  **
**                                                                          **
**   All rights reserved                                                    **
**                                                                          **
**   This program and the accompanying materials are made available under   **
**   the terms of the Eclipse Public License v1.0 which accompanies this    **
**   distribution, and is available at:                                     **
**   http://www.stehno.com/legal/epl-1_0.html                               **
**                                                                          **
**   A copy is found in the file license.txt.                               **
**                                                                          **
**   This copyright notice MUST APPEAR in all copies of the file!           **
**  **********************************************************************  */

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

public class Main {
    /**//from  w w w .j a  v  a  2s. c o m
     * Appends a child element with the given tag name to the specified parent node. If the parent node 
     * is the Document, it is used itself.
     *
     * @param parent the parent node
     * @param tagName the tag name
     * @return the new element with the given tag name that is a child of the parent node
     */
    public static Element appendElement(Node parent, String tagName) {
        return ((Element) parent
                .appendChild((parent.getOwnerDocument() != null ? parent.getOwnerDocument() : (Document) parent)
                        .createElement(tagName)));
    }
}

Related

  1. appendElement(Element parent, String tagName)
  2. appendElement(Element parent, String tagName, String value)
  3. appendElement(Element parent, String type)
  4. appendElement(Node parent, String name)
  5. appendElement(Node parent, String name)
  6. appendElementNS(Element parent, String namespaceURI, String localName)
  7. appendStringElement(Element parentElement, String nodeName, String nodeValue)
  8. appendText(Element parent, String content)
  9. appendTextElement(Element parent, String element, long value)