Java XML Element Create createElement(String tag, String textContent, Document xml)

Here you can find the source of createElement(String tag, String textContent, Document xml)

Description

Creates and returns an element with the specified tag and text content

License

Open Source License

Parameter

Parameter Description
tag the tag of the element
textContent the text content of the element
xml the Document to use to create the element

Return

The element with the specified tag and text content

Declaration

public static Element createElement(String tag, String textContent, Document xml) 

Method Source Code

//package com.java2s;
/*//  ww w. ja  v a 2s .  c  o m
 * PackJacket - GUI frontend to IzPack to make Java-based installers
 * Copyright (C) 2008 - 2009  Amandeep Grewal, Manodasan Wignarajah
 *
 * PackJacket is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * PackJacket is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PackJacket.  If not, see <http://www.gnu.org/licenses/>.
 */

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

public class Main {
    /**
     * Creates and returns an element with the specified tag and text content
     * @param tag the tag of the element
     * @param textContent the text content of the element
     * @param xml the Document to use to create the element
     * @return The element with the specified tag and text content
     */
    public static Element createElement(String tag, String textContent, Document xml) {
        Element element = xml.createElement(tag);
        //Sets the text content of the element
        element.setTextContent(textContent);
        return element;
    }
}

Related

  1. createElement(Node node, String name)
  2. createElement(Node parent, String tag)
  3. createElement(QName key)
  4. createElement(QName qName)
  5. createElement(String name, Object value, Document doc)
  6. createElement(String tagName, String text, Document doc)
  7. createElementAndText(Element parent, String elementName, String text)
  8. createElementInSameNamespace(Element parent, String localName)
  9. createElementInTempDocument(String name, String prefix, String namespaceURI)