Example usage for org.w3c.dom Text replaceData

List of usage examples for org.w3c.dom Text replaceData

Introduction

In this page you can find the example usage for org.w3c.dom Text replaceData.

Prototype

public void replaceData(int offset, int count, String arg) throws DOMException;

Source Link

Document

Replace the characters starting at the specified 16-bit unit offset with the specified string.

Usage

From source file:Main.java

public static void editTextbyInsertionandReplacement(Document doc) {
    Element root = doc.getDocumentElement();
    Element place = (Element) root.getFirstChild();
    Text name = (Text) place.getFirstChild().getFirstChild();
    Text directions = (Text) place.getLastChild().getFirstChild();

    // Inserting the word "black"
    //    name.insertData(offset," black");
    name.insertData(3, " black");

    // Replace "left" with "right"
    //directions.replaceData(offset,count,"right");
    directions.replaceData(3, 3, "right");
}

From source file:DOMEdit.java

public static void editTextbyInsertionandReplacement(Document doc) {
        Element root = doc.getDocumentElement();
        Element place = (Element) root.getFirstChild();
        Text name = (Text) place.getFirstChild().getFirstChild();
        Text directions = (Text) place.getLastChild().getFirstChild();

        // Inserting the word "black"
        //    name.insertData(offset," black");
        name.insertData(3, " black");

        // Replace "left" with "right"
        //directions.replaceData(offset,count,"right");
        directions.replaceData(3, 3, "right");
    }/*ww w  .  jav  a2  s.  c  om*/