Example usage for org.w3c.dom CharacterData substringData

List of usage examples for org.w3c.dom CharacterData substringData

Introduction

In this page you can find the example usage for org.w3c.dom CharacterData substringData.

Prototype

public String substringData(int offset, int count) throws DOMException;

Source Link

Document

Extracts a range of data from the node.

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.  j  a  v a2 s. co  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;

    cdata.setData("some data");
    int len = cdata.getLength();
    int offset = 5;
    len = 4;
    String s = cdata.substringData(offset, len);
}