Java XML Text Node Create addTextElement(final Document document, final Element parentDom, final String namespace, final String name, final String value)

Here you can find the source of addTextElement(final Document document, final Element parentDom, final String namespace, final String name, final String value)

Description

This method creates and adds a new XML Element with text value

License

Open Source License

Parameter

Parameter Description
document root document
parentDom parent node
namespace namespace
name element name
value element text node value

Return

added element

Declaration

public static Element addTextElement(final Document document, final Element parentDom, final String namespace,
        final String name, final String value) 

Method Source Code

//package com.java2s;
/**/*from   w  ww .java2  s  .c o  m*/
 * DSS - Digital Signature Services
 * Copyright (C) 2015 European Commission, provided under the CEF programme
 *
 * This file is part of the "DSS - Digital Signature Services" project.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

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

import org.w3c.dom.Text;

public class Main {
    /**
     * This method creates and adds a new XML {@code Element} with text value
     *
     * @param document  root document
     * @param parentDom parent node
     * @param namespace namespace
     * @param name      element name
     * @param value     element text node value
     * @return added element
     */
    public static Element addTextElement(final Document document, final Element parentDom, final String namespace,
            final String name, final String value) {

        final Element dom = document.createElementNS(namespace, name);
        parentDom.appendChild(dom);
        final Text valueNode = document.createTextNode(value);
        dom.appendChild(valueNode);
        return dom;
    }
}

Related

  1. addText(Document doc, Node node, String text)
  2. addText(Document doc, Node parent, String data)
  3. addTextElement(Document doc, String name, String value, Element parent)
  4. addTextElement(Document document, Node parentNode, String elementName, String elementText)
  5. addTextElement(final Document document, final Element parentDom, final String namespace, final String name, final String value)
  6. addTextNode(Document document, Element ret, String tag, String value)
  7. addTextNode(Document XMLDocument, Node rootElement, String tagName, String text)
  8. appendElementChild(Document doc, Element parent, String name)
  9. appendElementChildWithText(Document doc, Element parent, String name, String text)