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:-
| <?xml version="1.0"
encoding="UTF-8"?> <Company> <name>Rose India in Rohini</name> </Company> |
SplittingTextNode.java
/* |
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 |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Splitting One Text Node into Three View All Comments
Post your Comment