Java XML CDATA Append appendCDATAElement(Element parent, String tagName, String value)

Here you can find the source of appendCDATAElement(Element parent, String tagName, String value)

Description

append CDATA Element

License

Apache License

Declaration

public static Element appendCDATAElement(Element parent, String tagName, String value) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Main {
    public static Element appendCDATAElement(Element parent, String tagName, String value) {
        Element child = appendElement(parent, tagName);
        if (value == null) {
            value = "";
        }//from   w  ww .  j  a  v a2 s  .c  o  m
        Node cdata = child.getOwnerDocument().createCDATASection(value);
        child.appendChild(cdata);
        return child;
    }

    public static Element appendElement(Element parent, String tagName) {
        Element child = parent.getOwnerDocument().createElement(tagName);
        parent.appendChild(child);
        return child;
    }

    public static Element appendElement(Element parent, String tagName, String value) {
        Element child = appendElement(parent, tagName);
        child.appendChild(child.getOwnerDocument().createTextNode(value));
        return child;
    }

    public static void appendElement(Element parent, Element child) {
        Node tmp = parent.getOwnerDocument().importNode(child, true);
        parent.appendChild(tmp);
    }
}

Related

  1. appendCDATA(Element parent, String content)
  2. appendCDATAElement(Element parent, String name, String content)
  3. appendCDATAElement(Element parent, String tagName, String value)
  4. appendCDATASection(CDATASection cdataSection, StringBuffer buf)
  5. appendCDATASection(Node parent, String name, Object data)
  6. appendCDATASubNode(String elementName, String nodeData, Element parentElement, Document doc)