Add literal text to the supplied element. - Java XML

Java examples for XML:DOM Node

Description

Add literal text to the supplied element.

Demo Code

/*/* w  w w.j ava  2s  .  com*/
 * ePUB Corrector - https://github.com/vysokyj/epub-corrector/
 *
 * Copyright (C) 2012 Jiri Vysoky
 *
 * ePUB Corrector 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.
 *
 * ePUB Corrector 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 Cobertura; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */
//package com.java2s;
import org.w3c.dom.*;

public class Main {
    /**
     * Add literal text to the supplied element.
     *
     * @param element     Target DOM Element.
     * @param literalText Literal text to be added.
     */
    public static void addLiteral(Element element, String literalText) {

        Document document = element.getOwnerDocument();
        Text literal = document.createTextNode(literalText);
        element.appendChild(literal);
    }
}

Related Tutorials