Java XML Text Node Create createTextElement(final Document document, final String tagName, final String text)

Here you can find the source of createTextElement(final Document document, final String tagName, final String text)

Description

Creates an Element containing the given text

License

Open Source License

Parameter

Parameter Description
document the document to contain the new element
tagName the element's tag name (required)
text the text to set; can be <code>null</code> for none

Return

a non-null element

Declaration

public static Element createTextElement(final Document document,
        final String tagName, final String text) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**//from www.j a  v a  2  s .c o  m
     * Creates an {@link Element} containing the given text
     * 
     * @param document the document to contain the new element
     * @param tagName the element's tag name (required)
     * @param text the text to set; can be <code>null</code> for none
     * @return a non-<code>null</code> element
     * @since 1.2.0
     */
    public static Element createTextElement(final Document document,
            final String tagName, final String text) {
        final Element element = document.createElement(tagName);
        element.setTextContent(text);
        return element;
    }
}

Related

  1. createText(DocumentFragment fragment)
  2. createTextChildElement(Document doc, Node node, String name, String value)
  3. createTextElement(Document d, String textElementName, String textElementValue)
  4. createTextElement(Document doc, String elementName, String value)
  5. createTextElement(Document doc, String name, String content)
  6. createTextElement(QName qname, String value, Document doc)
  7. createTextLn(Document d, String text)
  8. createTextNode(Document _doc, String tagName, String tagValue)
  9. createTextNode(Document doc, Calendar cal, boolean dateOnly)