Java XML Element Create createElement(Element parent, String name)

Here you can find the source of createElement(Element parent, String name)

Description

Add a new element to the given parent

License

Educational Community License

Parameter

Parameter Description
parent the parent Element
name the child name

Return

new Element

Declaration

public static Element createElement(Element parent, String name) 

Method Source Code

//package com.java2s;
/**********************************************************************************
 *
 * Copyright (c) 2003, 2004, 2007, 2008 The Sakai Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.opensource.org/licenses/ECL-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.//w w  w. j a v  a2 s. co m
 *
 **********************************************************************************/

import org.w3c.dom.*;

public class Main {
    /**
     * Create a new element
     * @param document Document to contain the new element
     * @param name the element name
     * @return new Element
     */
    public static Element createElement(Document document, String name) {
        Element element;

        return document.createElement(name);
    }

    /**
     * Add a new element to the given parent
     * @param parent the parent Element
     * @param name the child name
     * @return new Element
     */
    public static Element createElement(Element parent, String name) {
        Document document;
        Element element;

        document = parent.getOwnerDocument();
        element = document.createElement(name);

        parent.appendChild(element);
        return element;
    }
}

Related

  1. createElement(Document dom, String elementName, Properties attributes)
  2. createElement(Document dom, String elementName, Properties attributes)
  3. createElement(Document owner, String nsURI, String elementName, String textValue)
  4. createElement(Element parent, String elementName)
  5. createElement(Element parent, String name)
  6. createElement(Element parent, String path)
  7. createElement(Element parent, String tagName)
  8. createElement(Element parent, String tagName)
  9. createElement(Element parent, String tagName, String value)