[jdom-interest] extract info from JDOM tree
Kenneth Ellefsen
kellefsen at bergen.oilfield.slb.com
Thu Dec 5 02:28:17 PST 2002
On Thu, 2002-12-05 at 10:42, Sylvain.Thevoz at swisscom.com wrote:
> Hello everybody,
>
> I repost my question:
>
> I have a XML file like this
> <document>
> <group name="Europe">
> <company name="LH">
> <fullname>Lufthansa</fullname>
> </company>
> <company name="SA">
> <fullname>Soviet Airlines</fullname>
> </company>
> <company name="AF">
> <fullname>Air France</fullname>
> </company>
> </group>
> <group name="US">
> <company name="AA">
> <fullname>American Airlines</fullname>
> </company>
> </group>
> </document>
>
>
> I want to retrieve content of this file and create a list of String that contain:
> Europe
> Europe->Lufthansa
> Europe->Soviet Airlines
> Europe->Air France
> US
> US->American Airlines
>
Shouldn't be to hard...
Element root = document.getRootNode();
List groups = root.getChildren("group");
ListIterator groupIterator = groups.listIterator();
ArrayList stringList = new ArrayList();
while(groupIterator.hasNext()){
Element group = (Element)groupIterator.next();
String groupName = group.getAttributeValue("name");
stringList.add(groupName);
List companies = group.getChildren("company");
ListIterator companyIterator = companies.listIterator();
while(companyIterator.hasNext()){
Element company = companyIterator.next();
companyName = company.getChildText("fullname");
stringList.add(groupName + "->" + companyName);
}
}
Or something like that.....I just wrote this from the top of my head, so
It may very well contain some errors ;)
Regards,
Kenneth
More information about the jdom-interest
mailing list