In this tutorial, we will see how to retrieve the value of an attribute in different data type like int, float, boolean etc with the help of JDOM library.
The JDOM libraries allows you to modify the value of node attribute in runtime. This examples shows how to set the value of node element. Here we are using org.jdom.Attribute class from the JDOM library.
The getValue() method of the org.jdom.Attribute class returns the text value of the attribute. This class is also providing other methods to get the values in the int, long, float etc. These methods try to convert the value in required format, if there is some data conversion error, it throws the DataConversionException exception.
Here is the xml file used in this example.
student.xml
<?xml version="1.0"?>
|
AttrDiffTypeValue .java
package roseindia;
|
|
Actual value of attribute : 5677 Int value of attribute : 5677 Double value of attribute : 5677.0 org.jdom.DataConversionException |
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.