Java XML CDATA Append appendCDATASubNode(String elementName, String nodeData, Element parentElement, Document doc)

Here you can find the source of appendCDATASubNode(String elementName, String nodeData, Element parentElement, Document doc)

Description

Creates a cdata node within a created element and then attaches the date to a parent.

License

Open Source License

Parameter

Parameter Description
elementName the name for the new element
nodeData the data for the new text node
parentElement the parent element
doc the document (root)

Declaration

public static void appendCDATASubNode(String elementName, String nodeData, Element parentElement,
        Document doc) 

Method Source Code

//package com.java2s;
/*//from  w w w. j  a  v  a  2s  . c o m
 * Copyright (c) 2015.
 *
 *     This file is part of VaSOLSim.
 *
 *     VaSOLSim 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.
 *
 *     VaSOLSim 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 VaSOLSim.  If not, see <http://www.gnu.org/licenses/>.
 */

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

public class Main {
    /**
     * Creates a cdata node within a created element and then attaches the date to a parent.
     *
     * @param elementName   the name for the new element
     * @param nodeData      the data for the new text node
     * @param parentElement the parent element
     * @param doc           the document (root)
     */
    public static void appendCDATASubNode(String elementName, String nodeData, Element parentElement,
            Document doc) {
        Element subElement = doc.createElement(elementName);
        subElement.appendChild(doc.createCDATASection(nodeData));
        parentElement.appendChild(subElement);
    }
}

Related

  1. appendCDATAElement(Element parent, String name, String content)
  2. appendCDATAElement(Element parent, String tagName, String value)
  3. appendCDATAElement(Element parent, String tagName, String value)
  4. appendCDATASection(CDATASection cdataSection, StringBuffer buf)
  5. appendCDATASection(Node parent, String name, Object data)
  6. setCDATA(Element element, String data)
  7. setCData(Element element, String data)