Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

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

Khorasani, Houman

2005-08-16

Replies:

Hello,

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"?>
<data>
 <row>
   <coffeeName>Esperesso</coffeeName>
   <coffeeDesc>Very Strong, very small</coffeeDesc>
 </row>
 <row>
   <coffeeName>Capuccino</coffeeName>
   <coffeeDesc>Not so strong, middle size</coffeeDesc>
 </row>
 <row>
   <coffeeName>Caffee Late</coffeeName>
   <coffeeDesc>Weak, big size</coffeeDesc>
 </row>
</data>


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();

System.out.println(getCoffeeDesc("Esperesso"));

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

Many Thanks
Houman



_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.