Source Code : Accessing Attributes Using JDOM
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Accessing Attributes Using JDOM
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.adapters.XercesDOMAdapter;
import org.jdom.input.DOMBuilder;
public class JDOMCreateExample {
private static DOMBuilder builder = null;
public static void main(String args[]) throws Exception, FileNotFoundException {
XercesDOMAdapter xercAdapter = new XercesDOMAdapter();
org.w3c.dom.Document w3Dom = xercAdapter.getDocument(new FileInputStream("games.xml"), false);
builder = new DOMBuilder("org.jdom.adapters.XercesDOMAdapter");
Document doc = builder.build(w3Dom);
List childs = doc.getRootElement().getChildren("game");
Iterator itr = childs.iterator();
while (itr.hasNext()) {
Element child = (Element) itr.next();
System.out.println(child.getName() + " = " + child.getText());
System.out.println(child.getAttributeValue("genre"));
}
}
}
Thank with us