Example usage for org.w3c.dom Text insertData

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

Introduction

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

Prototype

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

Source Link

Document

Insert a string at the specified 16-bit unit offset.

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.  j a  va2 s  .  c om*/