This Example describes a method to split a Text node into three new Node in a DOM document. Methods which are used for splitting of the text node in the DOM Document are described below :-
Element root = doc.getDocumentElement():-allows direct access to the root of the DOM document.
Element paragraph = (Element) root.getFirstChild():-creates a new node named paragraph and gets the child of the root in it.
Text newText = text.splitText(5):-This method splits the text node into two nodes at the specified offset.
Xml code for the program generated is:-
<name>Rose India in Rohini</name>
Output of the program:-
|Text node before spillting is: Rose India in Rohini
Spillted First node is: India in Rohini
Spillted Second node is: in Rohini
Spillted Third node is: Rohini
Liked it! Share this Tutorial