In this section we will discuss about how to add a Child Node in Dom document.
The addition of child node is a very logical. To add a child node first we create blank DOM document and then we create the root node using createElement() method . This root node is appended in the dom document using method appendChild().
After this step, we create child Node(element) for appending with the root node and we can set the attribute of the node by using method setAttribute("name","value") and append this child with the root node.
In this last step, we create the instance of TransformerFactory to create the object of the transformer class. This class is used to print the DOM tree (output) on the console.
The full code of the createchild.java:
Element childElement = doc.createElement("spring");
Output of the code:
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.