append CDATA Element - Java XML

Java examples for XML:CDATA

Description

append CDATA Element

Demo Code


//package com.java2s;
import org.w3c.dom.Element;
import org.w3c.dom.Document;

import org.w3c.dom.CDATASection;

public class Main {
    public static void appendCDATAElement(Document doc, Element parent,
            String name, String value) {
        Element el = newCDATAElement(doc, name, value);
        parent.appendChild(el);//w w  w.j  a  v  a 2 s . c o  m
    }

    public static Element newCDATAElement(Document doc, String nodeName,
            String value) {
        Element result = doc.createElement(nodeName);
        CDATASection cdata = doc.createCDATASection(value);
        result.appendChild(cdata);

        return result;
    }
}

Related Tutorials