Java XML Text Node Create createTextNode(Document doc, String elemName, String attrName, String attrValue, String content)

Here you can find the source of createTextNode(Document doc, String elemName, String attrName, String attrValue, String content)

Description

Creates node with given name appended by text node with content.

License

Open Source License

Parameter

Parameter Description
doc a parameter
elemName a parameter
attrName a parameter
attrValue a parameter
content a parameter

Declaration

public static Element createTextNode(Document doc, String elemName,
        String attrName, String attrValue, String content) 

Method Source Code

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

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

public class Main {
    /**//from   w w w  .ja v  a  2 s . com
     * Creates node with given name appended by text node with content. If not
     * null, adds given attribute.
     * 
     * @param doc
     * @param elemName
     * @param attrName
     * @param attrValue
     * @param content
     * @return
     */
    public static Element createTextNode(Document doc, String elemName,
            String attrName, String attrValue, String content) {

        Element element = doc.createElement(elemName);

        if (attrName != null && attrValue != null) {
            element.setAttribute(attrName, attrValue);
        }

        Text text = doc.createTextNode(content);
        element.appendChild(text);

        return element;
    }
}

Related

  1. createTextElement(final Document document, final String tagName, final String text)
  2. createTextElement(QName qname, String value, Document doc)
  3. createTextLn(Document d, String text)
  4. createTextNode(Document _doc, String tagName, String tagValue)
  5. createTextNode(Document doc, Calendar cal, boolean dateOnly)
  6. createTextNode(Document doc, String string)
  7. createTextNode(Element element, String nodeName, String textValue)
  8. createTextNode(Node doc, String elementName, String elementText)
  9. createTextNode(Node node, String data)