Example usage for org.w3c.dom Document createCDATASection

List of usage examples for org.w3c.dom Document createCDATASection

Introduction

In this page you can find the example usage for org.w3c.dom Document createCDATASection.

Prototype

public CDATASection createCDATASection(String data) throws DOMException;

Source Link

Document

Creates a CDATASection node whose value is the specified string.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);/*from   w w w .  jav a  2s.  c o m*/
    factory.setExpandEntityReferences(false);

    Document doc = factory.newDocumentBuilder().parse(new File("filename"));
    Element element = doc.getElementById("key1");
    CDATASection cdataNode = doc.createCDATASection("");
    Comment commentNode = doc.createComment("");
    Text textNode = doc.createTextNode("");

    // All three types of nodes implement the CharacterData interface
    CharacterData cdata = cdataNode;
    cdata = commentNode;
    cdata = textNode;

    // data

    int offset = 5;
    cdata.insertData(offset, "a ");
    cdata.appendData(" b");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);//from   ww  w  .j a  va2 s . c o  m
    factory.setExpandEntityReferences(false);

    Document doc = factory.newDocumentBuilder().parse(new File("filename"));
    Element element = doc.getElementById("key1");
    CDATASection cdataNode = doc.createCDATASection("");
    Comment commentNode = doc.createComment("");
    Text textNode = doc.createTextNode("");

    // All three types of nodes implement the CharacterData interface
    CharacterData cdata = cdataNode;
    cdata = commentNode;
    cdata = textNode;

    // Replace text
    String replacement = "c";
    int offset = 10;
    int len = 6;
    cdata.replaceData(offset, len, replacement);
}

From source file:Main.java

public static void insertText(Document doc, Node node, String text) {
    node.appendChild(doc.createCDATASection(text));
}

From source file:Main.java

public static void addCDATA(Document document, Node baseNode, String value) {
    CDATASection cdataSection = document.createCDATASection(value);
    baseNode.appendChild(cdataSection);// w  w w. j  a v a  2  s .c  o  m
}

From source file:Main.java

public static final void addNodeCDATAValue(Node node, String name, String value) {
    if (value != null) {
        Document doc = node.getOwnerDocument();
        Element e = doc.createElement(name);
        e.appendChild(doc.createCDATASection(value));
        node.appendChild(e);//w  ww . j  av a  2  s.  c  o m
    }
}

From source file:Main.java

private static Node createElementWithCDATA(Document doc, String tagName, String cdata) {
    Element node = doc.createElement(tagName);
    node.appendChild(doc.createCDATASection(cdata));

    return node;/*from  ww w  .  j ava  2 s.c  o  m*/
}

From source file:Main.java

public static Node getMagicNode(Document doc, String content) {
    Element magicNode = doc.createElement("KMagicNode");
    magicNode.appendChild(doc.createCDATASection(content));
    return magicNode;
}

From source file:Main.java

public static Element createNewCDATAElement(Node elem, String tag, String value) {
    Document doc = elem.getOwnerDocument();
    Element res = doc.createElement(tag);
    CDATASection cdata = doc.createCDATASection(value);
    res.appendChild(cdata);/*  w  ww  .  ja v  a  2  s.  c o  m*/
    elem.appendChild(res);
    return res;
}

From source file:Main.java

/**
 * Creates a <code>CDATASection</code> node whose value is the specified string.  This is different from 
 * Document.createCDATASection() in that this method first converts all "\r\n" and "\r" to "\n" to guard 
 * against XML "features" that transform "\r\n" to "\r\r\n" on output.
 * @param document/*from  w ww . j  av  a  2s .c o  m*/
 * @param data The data for the <code>CDATASection</code> contents.
 * @return The new <code>CDATASection</code> object.
 * @exception org.w3c.dom.DOMException
 *   NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
 */
public static CDATASection createCDATASection(Document document, String data) {
    String convertedData = convertNewLines(data);
    return document.createCDATASection(convertedData);
}

From source file:Main.java

public static Element createElemWithCDATA(Document ownerDoc, String tagName, String cdata) {
    Element newElem = ownerDoc.createElement(tagName);
    newElem.appendChild(ownerDoc.createCDATASection(cdata));
    return newElem;
}