In this tutorial, you will see how to set attribute of xml element in java.
In this tutorial, you will see how to set attribute of xml element in java.In this tutorial, we will see how to set attribute of
xml element in java with the help of
JDOM library. JDOM
is used for parsing, creating, manipulating, and serializing XML
documents.
In this example, we will use some methods.
DOMBuilder is a class that build a
JDOMDocument of xml file. The
getRootElement method of Document class is
used for accessing
root element. The setAttribute(String name, String value)
method set a attribute of an element with given name and value. The
Element class
is available in org.jdom.Element
pacakage.
Element API.
Return Type | Method | Description |
Element | setAttribute(String name, String value) | The setAttribute(.....) method set attribute of element. |
student.xml
<?xml version="1.0"?>
|
CloneAttribute.java
package roseindia;
|
Root Element[Element: <Student/>] Atttribute : [Attribute: id="001"] |