Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 30th, 2012  |  syntax: None  |  size: 1.93 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Java and parsing XML
  2. public class XMLHandler extends DefaultHandler {
  3.  
  4. private static final String MEASURES = "measures";
  5.  
  6. private static final String SUGARMEASUREDATE = "sugarMeasureDate";
  7. private static final String SUGARMEASUREVALUE = "sugarMeasureValue";
  8.  
  9. private static final String UPGYROSCOPEDATE = "upGyroscopeDate";
  10. private static final String UPGYROSCOPEVALUE = "upGyroscopeValue";
  11.  
  12. private static final String DOWNGYROSCOPEDATE = "downGyroscopeDate";
  13. private static final String DOWNGYROSCOPEVALUE = "downGyroscopeValue";
  14.  
  15. Boolean currentElement = false;
  16. String currentValue = null;
  17.  
  18. public static MeasureLists measureLists = null;
  19.  
  20. public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
  21.     currentElement = true;
  22.  
  23.     if (localName.equals("measures")) {
  24.         measureLists = new MeasureLists();
  25.     }
  26. }
  27.  
  28. public void endElement(String uri, String localName, String qName) throws SAXException {
  29.  
  30.     currentElement = false;
  31.     if (localName.equals(SUGARMEASUREDATE)) {
  32.         measureLists.setSugarDate(currentValue);
  33.     }
  34.     else if (localName.equals(SUGARMEASUREVALUE)) {
  35.         measureLists.setSugarValue(currentValue);
  36.     }
  37.     else if (localName.equals(UPGYROSCOPEDATE)) {
  38.         measureLists.setUpGyroscopeDate(currentValue);
  39.     }
  40.     else if (localName.equals(UPGYROSCOPEVALUE)) {
  41.         measureLists.setUpGyroscopeValue(currentValue);
  42.     }
  43.     else if (localName.equals(DOWNGYROSCOPEDATE)) {
  44.         measureLists.setDownGyroscopeDate(currentValue);
  45.     }
  46.     else if (localName.equals(DOWNGYROSCOPEVALUE)) {
  47.         measureLists.setDownGyroscopeValue(currentValue);
  48.     }
  49. }
  50.  
  51. public void characters(char[] ch, int start, int length) throws SAXException {
  52.  
  53.     if (currentElement) {
  54.         currentValue = new String(ch, start, length);
  55.         currentElement = false;
  56.     }
  57. }
  58.  
  59. public MeasureLists getMeasureLists() {
  60.     return measureLists;
  61. }
  62. }
  63.        
  64. html:va xmlns:html="www.google.com"