List of usage examples for org.w3c.dom Text splitText
public Text splitText(int offset) throws DOMException;
offset
, keeping both in the tree as siblings. 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); }