FileDocCategorySizeDatePackage
TestJDOM.javaAPI DocExample914Sat Apr 23 22:35:34 BST 2005None

TestJDOM

public class TestJDOM extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

		Document doc = new SAXBuilder().build("zooinventory.xml");
		List animals = doc.getRootElement().getChildren("Animal");
		System.out.println("Animals = ");
		for( int i=0; i<animals.size(); i++ ) {
			String name = ((Element)animals.get(i)).getChildText("Name");
			String species = ((Element)animals.get(i)).getChildText("Species");
			System.out.println( "  "+ name +" ("+species+")" );
		}
		Element foodRecipe = ((Element)animals.get(1)).getChild("FoodRecipe");
		String name = foodRecipe.getChildText("Name");
		System.out.println("Recipe = " + name );
		List ingredients = foodRecipe.getChildren("Ingredient");
		for(int i=0; i<ingredients.size(); i++) 
			System.out.println( "  "+((Element)ingredients.get(i)).getText() );