This Example shows you how to Change the Content of a 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:-
Element root = doc.getDocumentElement():-direct access to the root of the DOM document.
NodeList childnodelist = root.getChildNodes():-created a childnodelist and get the collection of child nodes of this node.
Xml code for the program generated is:-
| <?xml version="1.0"
encoding="UTF-8"?> <Company> <Employee> <Employeename>Girish Tewari</Employeename> <email>girish@gmail.com</email> </Employee> <Employee> <Employeename>Komal</Employeename> <email>Komal@gmail.com</email> </Employee> <Employee> <Employeename>Mahendra</Employeename> <email>dhoni@gmail.com</email> </Employee> </Company> |
Changecontent.java :-
/* |
Output of the program:-
| email Old e-mail id: girish@gmail.com New e-mail id: @Rose.com |
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: Locate a Node and Change Its Content
Post your Comment