Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 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 cvicenie3.sax;
  7.  
  8. import org.xml.sax.Attributes;
  9. import org.xml.sax.SAXException;
  10. import org.xml.sax.helpers.DefaultHandler;
  11.  
  12. /**
  13.  *
  14.  * @author patyi
  15.  */
  16. class MyHandler extends DefaultHandler {
  17.    
  18.     String text;
  19.    
  20.     boolean inNazov1 = false;
  21.     boolean inNazov2 = false;
  22.     boolean inPolozka = false;
  23.    
  24.     public void startDocument(){
  25.         System.out.println("Vitaj v mojom receptari VSA");
  26.     }
  27.    
  28.    
  29.     @Override
  30.     public void characters(char[] ch, int start, int length) throws SAXException {
  31.         text = new String(ch, start, length); //To change body of generated methods, choose Tools | Templates.
  32.     }
  33.  
  34.         @Override
  35.     public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
  36.          if (localName.equals("polozka"))
  37.         {
  38.             inPolozka = true;
  39.         }
  40.        
  41. //        if (localName.equals("nazov") && (inPolozka = false))
  42. //        {
  43. //            System.out.println("Nazov receptu je" + text);
  44. //        }
  45.        
  46.        
  47.        
  48. //        if (localName.equals("nazov") && (inPolozka = true))
  49. //        {
  50. //            inNazov2 = true;
  51. //        }
  52.        
  53.        
  54.        
  55.        
  56.        
  57.        
  58.     }
  59.    
  60.     @Override
  61.     public void endElement(String uri, String localName, String qName) throws SAXException {
  62.          if (localName.equals("polozka"))
  63.         {
  64.             inPolozka = false;
  65.         }
  66.        
  67.         if (localName.equals("nazov") && (inPolozka = false)){
  68.            
  69.             System.out.println("Recept" + text);
  70.         }
  71.        
  72.        
  73.        
  74.         if (localName.equals("nazov") && (inPolozka = true)){
  75.             System.out.println("Ingrediencia: " + text);
  76.            
  77.         }
  78.        
  79.        
  80.        
  81.        
  82.        
  83.        
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement