Java XML Child Element Add addAsFirstChild(Element element, Element newChild)

Here you can find the source of addAsFirstChild(Element element, Element newChild)

Description

add As First Child

License

Open Source License

Declaration

public static void addAsFirstChild(Element element, Element newChild) 

Method Source Code

//package com.java2s;
/**//  w  w  w.j  a  va 2  s.co m
 * This file belongs to the BPELUnit utility and Eclipse plugin set. See enclosed
 * license file for more information.
 */

import org.w3c.dom.Element;

public class Main {
    public static void addAsFirstChild(Element element, Element newChild) {
        if (element.hasChildNodes()) {
            element.insertBefore(newChild, element.getChildNodes().item(0));
        } else {
            element.appendChild(newChild);
        }
    }
}

Related

  1. AddChild(Element parent, String nodename)
  2. addChild(final Node node, final Node child)
  3. addChild(Node parent, Node child)
  4. addChild(Node parent, String name, String text)