Java XML Child Insert insertAfter(Node newChild, Node refChild)

Here you can find the source of insertAfter(Node newChild, Node refChild)

Description

__UNDOCUMENTED__

License

BSD License

Parameter

Parameter Description
newChild __UNDOCUMENTED__
refChild __UNDOCUMENTED__

Exception

Parameter Description
DOMException __UNDOCUMENTED__

Declaration

public static void insertAfter(Node newChild, Node refChild) throws DOMException 

Method Source Code


//package com.java2s;
/*//w  ww.ja  va 2  s  . c  om
 * Copyright (c) 2012. betterFORM Project - http://www.betterform.de
 * Licensed under the terms of BSD License
 */

import org.w3c.dom.*;

public class Main {
    /**
     * __UNDOCUMENTED__
     *
     * @param newChild __UNDOCUMENTED__
     * @param refChild __UNDOCUMENTED__
     * @throws DOMException __UNDOCUMENTED__
     */
    public static void insertAfter(Node newChild, Node refChild) throws DOMException {
        if (refChild == null) {
            throw new DOMException(DOMException.NOT_FOUND_ERR, "refChild == null");
        }

        Node nextSibling = refChild.getNextSibling();

        if (nextSibling == null) {
            refChild.getParentNode().appendChild(newChild);
        } else {
            refChild.getParentNode().insertBefore(newChild, nextSibling);
        }
    }
}

Related

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