This Example shows you how to Replace a node with existing node in a DOM document. JAXP (Java API for XML Processing) is an interface which provides parsing of xml documents. Here the Document BuilderFactory is used to create new DOM parsers. These are some of the methods used in code given below for adding attribute:-
root.getFirstChild().getFirstChild().getNodeName():-Access the subchild name of the root.
Node schild = fchild.getNextSibling():-it returns the node immediately following the node fchild.
root.replaceChild(schild, fchild):-This method replaces a child node with another.
Xml code for the program generated is:-
<?xml version="1.0" encoding="UTF-8"?>
<Company>
<Location>
<Companyname>Roseindia .Net</Companyname>
<Employee>Girish Tewari</Employee>
</Location>
<Id></Id>>
</Company>
|
Replacenode.java
/* |
Output of the program:-
Node before replacing is :Companyname Node after replacing name is:Id |
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: Replacing a Node with a New One View All Comments
Post your Comment