...
Code Block |
---|
//Create a generatic unmarshaller
javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance("generated");
javax.xml.bind.Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller();
//Read in the species.xml file and parse it into a Codes object.
FileInputStream input = new FileInputStream("species.xml" );
Codes codes =(Codes)unmarshaller.unmarshal(input);
//Get the list of species contained within the codes object, iterate over the list and display the species codes and names found therein.
List<SpeciesDef> species = codes.getSpeciesDef();
for(SpeciesDef speciesDef:species){
System.out.println("Species "+speciesDef.getSpecies().getName()+" -- "+speciesDef.getSpecies().getValue().toString());
}
|
...