[jdom-interest] return specific XML node within a for-loop

Khorasani, Houman houman_khorasani at csgsystems.com
Tue Aug 16 07:40:47 PDT 2005


I am new to JDOM and would like to know how I could solve this.
I have an existing XML file like this:

<?xml version="1.0" encoding="UTF-8"?>
		<coffeeDesc>Very Strong, very small</coffeeDesc>
		<coffeeDesc>Not so strong, middle size</coffeeDesc>
		<coffeeName>Caffee Late</coffeeName>
		<coffeeDesc>Weak, big size</coffeeDesc>

I would like to have a method that contains a for-loop and return the
description for the coffeeName.

public String getCoffeeDesc(String coffeeName) {

SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new File("C://dev//coffee.xml"));
Element root = doc.getRootElement();
List children = root.getChildren();


I have all the children of root within "children" but how shall I
proceed at this point the best way?   

Many Thanks

More information about the jdom-interest mailing list