Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package cvicenie3.sax;
- import org.xml.sax.Attributes;
- import org.xml.sax.SAXException;
- import org.xml.sax.helpers.DefaultHandler;
- /**
- *
- * @author patyi
- */
- class MyHandler extends DefaultHandler {
- String text;
- boolean inNazov1 = false;
- boolean inNazov2 = false;
- boolean inPolozka = false;
- public void startDocument(){
- System.out.println("Vitaj v mojom receptari VSA");
- }
- @Override
- public void characters(char[] ch, int start, int length) throws SAXException {
- text = new String(ch, start, length); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
- if (localName.equals("polozka"))
- {
- inPolozka = true;
- }
- // if (localName.equals("nazov") && (inPolozka = false))
- // {
- // System.out.println("Nazov receptu je" + text);
- // }
- // if (localName.equals("nazov") && (inPolozka = true))
- // {
- // inNazov2 = true;
- // }
- }
- @Override
- public void endElement(String uri, String localName, String qName) throws SAXException {
- if (localName.equals("polozka"))
- {
- inPolozka = false;
- }
- if (localName.equals("nazov") && (inPolozka = false)){
- System.out.println("Recept" + text);
- }
- if (localName.equals("nazov") && (inPolozka = true)){
- System.out.println("Ingrediencia: " + text);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement