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.
- */
- import org.xml.sax.Attributes;
- import org.xml.sax.SAXException;
- import org.xml.sax.helpers.DefaultHandler;
- /**
- *
- * @author Lukáš
- */
- public class Handlerr extends DefaultHandler {
- String text = null;
- String menoNajdrahsej = null;
- String edicia = null;
- boolean isKniha = false;
- boolean isFound = false;
- boolean isStopy = false;
- float cena1 = 0;
- float cena2 = 0;
- @Override
- public void characters(char[] ch, int start, int length) throws SAXException {
- text = new String(ch, start, length);
- }
- @Override
- public void endElement(String uri, String localName, String qName) throws SAXException {
- if(localName.equals("meno") && isKniha)
- {
- menoNajdrahsej = text;
- }
- if(localName.equals("cena") && isStopy)
- {
- cena1 = Float.parseFloat(text);
- if(cena1 > cena2)
- {
- cena2 = cena1;
- isFound = true;
- }
- cena1 = 0;
- }
- if(localName.equals("kniha") && isStopy)
- {
- isKniha = false;
- if(isFound)
- {
- System.out.println(menoNajdrahsej);
- System.out.println(cena2);
- }
- else
- {
- System.out.println("neexistuje");
- }
- isStopy = false;
- isFound = false;
- }
- }
- @Override
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
- if(localName.equals("kniha"))
- {
- edicia = attributes.getValue("edicia");
- if(edicia != null && edicia.equals("Stopy"))
- {
- isStopy = true;
- }
- isKniha = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement