Guest User

ตัวอย่างการ Unmarshalled

a guest
Sep 12th, 2011
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. import generated.Address;
  2. import generated.Human;
  3. import generated.ObjectFactory;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileOutputStream;
  6. import java.util.logging.Level;
  7. import java.util.logging.Logger;
  8. public class Main {
  9.     public static void main(String[] args) {
  10.     Human h2 = new ObjectFactory().createHuman();
  11.         try {
  12.             javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(h2.getClass().getPackage().getName());
  13.             javax.xml.bind.Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller();
  14.             System.out.println("\n========= Input File =========\n");
  15.             h2 = (Human) unmarshaller.unmarshal(new java.io.File("C://web/me.xml")); //NOI18N
  16.             System.out.println("FirstName : "+h2.getFirstName());
  17.             System.out.println("SurName : "+h2.getSurName());
  18.             System.out.println("Sex : "+h2.getSex());
  19.             System.out.println("Ages : "+h2.getAge());
  20.             Address add2 = h2.getAddress();
  21.             System.out.println("Home number : "+add2.getHomenumber());
  22.             System.out.println("Street :"+add2.getStreet());
  23.             System.out.println("Tumbol : "+add2.getTumbol());
  24.             System.out.println("Amphur : "+add2.getAmphur());
  25.             System.out.println("Province : "+add2.getProvince());
  26.             System.out.println("Postcode : "+add2.getPostcode());
  27.         } catch (javax.xml.bind.JAXBException ex) {
  28.             System.out.println("File not found");
  29.             //java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, null, ex); //NOI18N
  30.         }
  31.  
  32.     } // end main
  33.  
  34. } // end class
Advertisement
Add Comment
Please, Sign In to add comment