Advertisement
Guest User

App.java

a guest
May 20th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package javaapplication13;
  7.  
  8. import java.io.FileNotFoundException;
  9. import java.io.FileReader;
  10. import javaapplication13.Receptar.Polozka;
  11. import javaapplication13.Receptar.Recept;
  12. import javax.xml.bind.JAXBContext;
  13. import javax.xml.bind.JAXBException;
  14. import javax.xml.bind.Unmarshaller;
  15.  
  16. /**
  17.  *
  18.  * @author danielplaskur
  19.  */
  20. public class JavaApplication13 {
  21.  
  22.     /**
  23.      * @param args the command line arguments
  24.      * @throws javax.xml.bind.JAXBException
  25.      * @throws java.io.FileNotFoundException
  26.      */
  27.     public static void main(String[] args) throws JAXBException, FileNotFoundException {
  28.         JAXBContext jb = JAXBContext.newInstance(Receptar.class);
  29.         Unmarshaller um = jb.createUnmarshaller();
  30.         Receptar receptar = (Receptar) um.unmarshal(new FileReader("/Users/danielplaskur/NetBeansProjects/skuskaSAX/input2.xml"));
  31.        
  32.         for(Recept r : receptar.getRecepty()){
  33.             for(Polozka p : r.getPolozky()){
  34.                 if(p.getNazov().equals("muka")){
  35.                     System.out.println(r.getNazov());
  36.                 }
  37.                 if(r.getNazov().equals("omeleta")){
  38.                     if(p.getNazov().equals("mlieko")){
  39.                         System.out.println(p.getMnozstvo() + " " + p.getJednotka());
  40.                     }
  41.                 }
  42.             }
  43.         }
  44.     }
  45.    
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement