import net.sourceforge.jaxme.address.ClsAddress; import net.sourceforge.jaxme.address.ClsAddressHandler; import net.sourceforge.jaxme.address.ClsName; import net.sourceforge.jaxme.address.ClsPostal; import net.sourceforge.jaxme.address.ClsPhone; import net.sourceforge.jaxme.address.ClsEmail; import de.ispsoft.jaxme.JMFileManager; public class AddressPrinter { public static void main(String[] args) throws Exception { // Instantiate a JMFileManager and set its SAX content handler // to the generated class ClsAddressHandler. This glues the // reading of an XML input document to the parsing code. JMFileManager manager = new JMFileManager(); manager.setJMContentHandlerClass(ClsAddressHandler.class); // Loop over XML documents within the file. for (java.util.Iterator iter = manager.select("Address.xml"); iter.hasNext(); ) { // Each iteration returns a generic iteration object, // which we must first cast to the generated class // ClsAddress. Then we have access to its internal // members which automatically contain the file's XML // content. ClsAddress ca = (ClsAddress) iter.next(); System.out.println ("eName.eFirst = " + ca.eName.eFirst); if (ca.eName.eMiddle != null) System.out.println ("eName.eMiddle = " + ca.eName.eMiddle); System.out.println ("eName.eLast = " + ca.eName.eLast); if (ca.eName.eInitials != null) System.out.println ("eName.eInitials = " + ca.eName.eInitials); System.out.println ("ePostal.eStreet = " + ca.ePostal.eStreet); System.out.println ("ePostal.eCity = " + ca.ePostal.eCity); System.out.println ("ePostal.eZip = " + ca.ePostal.eZIP); if (ca.ePostal.eState != null) System.out.println ("ePostal.eState = " + ca.ePostal.eState); if (ca.ePostal.eCountry != null) System.out.println ("ePostal.eCountry = " + ca.ePostal.eCountry); if (ca.ePhoneDetails != null) { for (java.util.Iterator phoneIter = ca.ePhoneDetails.ePhone.iterator(); phoneIter.hasNext(); ) { ClsPhone ePhone = (ClsPhone) phoneIter.next(); // Note: aType is a required attribute, so no need // to check for null. System.out.println ("ePhoneDetails.ePhone.aType = " + ePhone.aType); System.out.println ("ePhoneDetails.ePhone.ePhoneNumber = " + ePhone.ePhoneNumber); } } if (ca.eEmailDetails != null) { for (java.util.Iterator eMailIter = ca.eEmailDetails.eEmail.iterator(); eMailIter.hasNext(); ) { ClsEmail eMail = (ClsEmail) eMailIter.next(); // Note: aType is a required attribute, so no need // to check for null. System.out.println ("eMailDetails.eMail.aType = " + eMail.aType); System.out.println ("eMailDetails.eMail.eEmailAddress = " + eMail.eEmailAddress); } } } } }