Advertisement
Guest User

blabla

a guest
Mar 31st, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 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. import org.xml.sax.Attributes;
  7. import org.xml.sax.SAXException;
  8. import org.xml.sax.helpers.DefaultHandler;
  9.  
  10. /**
  11. *
  12. * @author Lukáš
  13. */
  14. public class Handlerr extends DefaultHandler {
  15.  
  16. String text = null;
  17. String menoNajdrahsej = null;
  18. String edicia = null;
  19.  
  20. boolean isKniha = false;
  21. boolean isFound = false;
  22. boolean isStopy = false;
  23.  
  24. float cena1 = 0;
  25. float cena2 = 0;
  26.  
  27.  
  28. @Override
  29. public void characters(char[] ch, int start, int length) throws SAXException {
  30.  
  31. text = new String(ch, start, length);
  32. }
  33.  
  34. @Override
  35. public void endElement(String uri, String localName, String qName) throws SAXException {
  36.  
  37. if(localName.equals("meno") && isKniha)
  38. {
  39. menoNajdrahsej = text;
  40. }
  41. if(localName.equals("cena") && isStopy)
  42. {
  43. cena1 = Float.parseFloat(text);
  44. if(cena1 > cena2)
  45. {
  46. cena2 = cena1;
  47. isFound = true;
  48. }
  49. cena1 = 0;
  50. }
  51. if(localName.equals("kniha") && isStopy)
  52. {
  53. isKniha = false;
  54. if(isFound)
  55. {
  56. System.out.println(menoNajdrahsej);
  57. System.out.println(cena2);
  58. }
  59. else
  60. {
  61. System.out.println("neexistuje");
  62. }
  63. isStopy = false;
  64. isFound = false;
  65. }
  66.  
  67. }
  68.  
  69. @Override
  70. public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
  71.  
  72.  
  73. if(localName.equals("kniha"))
  74. {
  75. edicia = attributes.getValue("edicia");
  76.  
  77. if(edicia != null && edicia.equals("Stopy"))
  78. {
  79. isStopy = true;
  80. }
  81.  
  82. isKniha = true;
  83. }
  84. }
  85.  
  86.  
  87.  
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement