FileDocCategorySizeDatePackage
TestJAXBUnmarshall.javaAPI DocExample952Sat Apr 23 22:35:42 BST 2005None

TestJAXBUnmarshall

public class TestJAXBUnmarshall extends Object

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

		JAXBContext jbcontext = JAXBContext.newInstance("learningjava");
		Unmarshaller unmarshaller = jbcontext.createUnmarshaller();
		// unmarshaller.setValidating(true);

		InventoryType inventory = (InventoryType)unmarshaller.unmarshal( 
			new File("zooinventory.xml") );

		System.out.println( "Animals = " );
		List<AnimalType> animals = inventory.getAnimal();
		for( AnimalType animal : animals )
			System.out.println( "\t"+animal.getName() );
		AnimalType cocoa = (AnimalType)(inventory.getAnimal().get(1));
		FoodRecipeType recipe = cocoa.getFoodRecipe();
		System.out.println( "Recipe = " + recipe.getName() );
		List<String> ingredients = recipe.getIngredient();
		for( String ingredient : ingredients )
			System.out.println( "\t"+ingredient );