Share on Google+Share on Google+

JDOM Attribute Example, Different method of Attribute class.

In this tutorial, you will see the use of different method of Attribute class.

JDOM Attribute Example, Different method of Attribute class.

This tutorial explains the use of the  getParent() and getQualifiedName(). These methods are present in the Attribute class. The Attribute class is available part of JDOM library.

Example discussed in this section explains the use of getPatent() and getQualifiedName() methods. After reading the examples you will be able to apply the logic to use correctly in your program.

The getChild(java.lang.String name) method of Element class returns the child element.
The getParent() method of Attribute class returns parent of the associated attribute.
The getQualifiedName() method of Attribute class returns name of attribute.

We will be using the following XML file.


<?xml version="1.0" encoding="UTF-8"?>
    <book >

package roseindia;
import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.DOMBuilder;

public class DifferentMethod {
  public static void main(String[] args) {
    try {
      String data = "book.xml";
      File file = new File(data);
      DOMBuilder domBuilder = new DOMBuilder();
      Document doc =;
      Element rootEl = doc.getRootElement();
      Element attElement = rootEl.getChild("book");
     System.out.println("Child Name of root : " + attElement);
      Attribute attribute = attElement.getAttribute("id");
           Element parent = attribute.getParent();
      String attributeName = attribute.getQualifiedName();
      System.out.println("Parent of attribute : " + parent);
      System.out.println("Name of attribute : " 
+ attributeName);
    catch (Exception ex) {
      System.out.println("Execption " + ex);


Child Name of root: [Element: <book/>]
Parent of attribute : [Element: <book/>]
 Name of attribute : id

Download this code


Posted on: August 20, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null