Java XML Child Element Create addChildElementValue(Element element, String childElementName, String childElementValue, Document document)

Here you can find the source of addChildElementValue(Element element, String childElementName, String childElementValue, Document document)

Description

Creates a child element with the given name and appends it to the element child node list.

License

Open Source License

Declaration

public static Element addChildElementValue(Element element, String childElementName, String childElementValue,
        Document document) 

Method Source Code


//package com.java2s;
/*//from   w w  w .  j  a va2 s  . c o  m
 * XMLUtils.java
 *
 * Copyright (c) 1998 - 2006 BusinessTechnology, Ltd.
 * All rights reserved
 *
 * This program is the proprietary and confidential information
 * of BusinessTechnology, Ltd. and may be used and disclosed only
 * as authorized in a license agreement authorizing and
 * controlling such use and disclosure
 *
 * Millennium ERP system.
 *
 */

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

public class Main {
    /**
     * Creates a child element with the given name and appends it to the element child node list. Also
     * creates a Text node with the given value and appends it to the new elements child node list.
     */
    public static Element addChildElementValue(Element element, String childElementName, String childElementValue,
            Document document) {
        Element newElement = addChildElement(element, childElementName, document);

        newElement.appendChild(document.createTextNode(childElementValue));
        return newElement;
    }

    /**
     * Creates a child element with the given name and appends it to the element child node list.
     */
    public static Element addChildElement(Element element, String childElementName, Document document) {
        Element newElement = document.createElement(childElementName);

        element.appendChild(newElement);
        return newElement;
    }
}

Related

  1. addChild(final Document doc, Element parent, final String childName, final String childValue)
  2. addChildElement(Document doc, Node parent, String tag)
  3. addChildElement(Document document, String elementName, Node parentNode)
  4. addChildElement(Element element, String childElementName, Document document)
  5. addChildElementNSElement(Element element, String childElementName, Document document, String nameSpaceUrl)
  6. addChildElementValue(Element element, String childElementName, String childElementValue, Document document)
  7. addChildEpcList(final Document document, final Element root, final String childEPCs)
  8. addChildNode(Document doc, Node parentNode, String childName, String childValue)
  9. addChildText(Document doc, Element parent, String textValue)