In this section, you will learn to remove any element from a given XML document. Whenever you remove the xml element from the xml document the data are also lost from the xml element.
Description of program:
This program takes a XML file name on the console. At the run time the program asks for an element name to be deleted. The removeChild() method removes the given element from the XML document by invoking the getParentNode() method .
Here is the XML File:E-mail.xml
| <?xml version="1.0"?> <E-mail> <To>Rohan</To> <From>Amit</From> <Subject>Surprise....</Subject> <Body>Be ready for a cruise...</Body> </E-mail> |
Here is the Java File: RemoveElement.java
import java.io.*;
|
Output of this program:
| C:\vinod\xml>javac RemoveElement.java C:\vinod\xml>java RemoveElement Enter a XML file name: E-mail.xml Enter an element which have to delete: Subject <?xml version="1.0" encoding="UTF-8" standalone="no"?><E-mail> <To>Rohan</To> <From>Amit</From> <Body>Be ready for a cruise...</Body> </E-mail> |
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: Remove Element from XML Document View All Comments
Post your Comment