Java XML Duration Add addElementFirst(final Element parent, final String name)

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

Description

Create a new element and add it as the first child

License

Open Source License

Parameter

Parameter Description
parent the parent to which to add the element
name the name of the element

Return

the new element

Declaration

public static Element addElementFirst(final Element parent, final String name) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014, 2015 IBH SYSTEMS GmbH.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://  www . jav a  2s .c o  m
 *     IBH SYSTEMS GmbH - initial API and implementation
 *******************************************************************************/

import org.w3c.dom.Element;

public class Main {
    /**
     * Create a new element and add it as the first child
     *
     * @param parent
     *            the parent to which to add the element
     * @param name
     *            the name of the element
     * @return the new element
     */
    public static Element addElementFirst(final Element parent, final String name) {
        final Element ele = parent.getOwnerDocument().createElement(name);
        parent.insertBefore(ele, null);
        return ele;
    }
}

Related

  1. addElement(Element parent, String tagName)
  2. addElement(final Element parent, final String name, final Object value)
  3. addElement(Node parent, String elementName)
  4. addElement(Node parent, String name)
  5. addElement(String name, Element parent)
  6. addElementFirst(final Element parent, final String name)
  7. addLongElementNS(Element parent, String namespaceURI, String tag, long value)
  8. addNamespacePrefix(Element parent, String namespace, String basePrefix)
  9. addNode(Element parent, String elementName, String namespaceURI)