Example usage for org.w3c.dom Text splitText

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

Introduction

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

Prototype

public Text splitText(int offset) throws DOMException;

Source Link

Document

Breaks this node into two nodes at the specified offset, keeping both in the tree as siblings.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);//  w  ww  .  j a  va 2 s  .c o m

    factory.setExpandEntityReferences(false);

    Document doc = factory.newDocumentBuilder().parse(new File("filename"));

    Element element = doc.getDocumentElement();

    Text text1 = (Text) element.getFirstChild();
    String string = text1.getData();

    String word = "some";
    Text text2 = text1.splitText(string.indexOf(word));
}

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 ava  2s .c om

    factory.setExpandEntityReferences(false);

    Document doc = factory.newDocumentBuilder().parse(new File("filename"));

    Element element = doc.getDocumentElement();

    Text text1 = (Text) element.getFirstChild();
    String string = text1.getData();
    String word = "some";
    Text text2 = text1.splitText(string.indexOf(word));

    Element newElement = doc.createElement("b");
    newElement.appendChild(text2);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);/*w w  w. ja  va  2s  . c o m*/

    factory.setExpandEntityReferences(false);

    Document doc = factory.newDocumentBuilder().parse(new File("filename"));

    Element element = doc.getDocumentElement();

    Text text1 = (Text) element.getFirstChild();
    String string = text1.getData();
    String word = "some";
    Text text2 = text1.splitText(string.indexOf(word));

    Element newElement = doc.createElement("b");
    newElement.appendChild(text2);

    element.insertBefore(newElement, text2);
}