Java XML Duration Add addElement(Node parent, String elementName)

Here you can find the source of addElement(Node parent, String elementName)

Description

Add an Element node to the supplied parent name.

License

Open Source License

Parameter

Parameter Description
parent The parent to to which the new Element node is to be added.
elementName The name of the Element to be added.

Return

The new Element.

Declaration

public static Element addElement(Node parent, String elementName) 

Method Source Code

//package com.java2s;
// License as published by the Free Software Foundation; either

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

import org.w3c.dom.Node;

public class Main {
    /**//from   www .j  av a2  s .c  o m
    * Add an Element node to the supplied parent name.
    * @param parent The parent to to which the new Element node is to be added.
    * @param elementName The name of the Element to be added.
    * @return The new Element.
    */
    public static Element addElement(Node parent, String elementName) {
        Element element = null;

        if (parent instanceof Document) {
            element = ((Document) parent).createElement(elementName);
        } else {
            element = parent.getOwnerDocument().createElement(elementName);
        }
        parent.appendChild(element);

        return element;
    }
}

Related

  1. add(Duration d1, Duration d2)
  2. add(Duration... durations)
  3. addElement(Element parent, String name)
  4. addElement(Element parent, String tagName)
  5. addElement(final Element parent, final String name, final Object value)
  6. addElement(Node parent, String name)
  7. addElement(String name, Element parent)
  8. addElementFirst(final Element parent, final String name)
  9. addElementFirst(final Element parent, final String name)