In this tutorial, you will see how to remove child of an element from xml file in java.
In this tutorial, you will see how to remove child of an element from xml file in java.In this tutorial, we will see how to remove child of an element from xml file in
java with the help of
JDOM library. JDOM is a java toolkit for
manipulating,
creating and serializing xml file.
With the help of this java code, we can remove a child
of given element. The
DOMBuilder class is used for creating DOM
tree. The getRootElement
method returns root of document. The
removeChild(String name) method
of Element class is used for
removing child of an element.
Element API.
Return Type | Method | Description |
boolean | removeChild(String name) | The removeChild(...) method remove child element of given name from existing xml file. |
student.xml
<?xml version="1.0"?>
|
CloneAttribute.java
package roseindia;
|
After removing element xml file. <?xml version="1.0" encoding="UTF-8"?> <Student> first id="20" name="ankit"> <city>lko</city> </first> <first id="30" name="gyan"> <city>lko</city> </first> </Student> |