Here you can find the source of appendCDATASubNode(String elementName, String nodeData, Element parentElement, Document doc)
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) |
public static void appendCDATASubNode(String elementName, String nodeData, Element parentElement, Document doc)
//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); } }