Java XML Child Insert prependChild(Element parent, Element child)

Here you can find the source of prependChild(Element parent, Element child)

Description

adds a child at the first place

License

LGPL

Parameter

Parameter Description
parent a parameter
child a parameter

Declaration

public static void prependChild(Element parent, Element child) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import org.w3c.dom.Element;

import org.w3c.dom.Node;

public class Main {
    /**/* ww w  . j  a  va  2s  .c  om*/
     * adds a child at the first place 
     * @param parent
     * @param child
     */
    public static void prependChild(Element parent, Element child) {
        Node first = parent.getFirstChild();
        if (first == null)
            parent.appendChild(child);
        else {
            parent.insertBefore(child, first);
        }
    }
}

Related

  1. insertAfter(Node newChild, Node refChild)
  2. insertAfter(Node parent, Node newChild, Node refChild)
  3. prependChildElement(Element parent, Element child)
  4. prependChildElement(Element parent, Element child)