public void endElement(String uri, String localName, String qName) throws SAXException { super.endElement(uri, localName, qName); if (qName.equals("available")) { available = Integer.parseInt(current.toString()); infoStation.setAvailable(available); } else if (qName.equals("free")) { free = Integer.parseInt(current.toString()); infoStation.setFree(free); } else if (qName.equals("total")) { total = Integer.parseInt(current.toString()); infoStation.setTotal(total); } else if (qName.equals("ticket")) { if (Integer.parseInt(current.toString()) == 1) ticket = true; else ticket = false; infoStation.setTicket(ticket); } else if (qName.equals("open")) { if (Integer.parseInt(current.toString()) == 1) open = true; else open = false; infoStation.setOpen(open); infoStation.setStationVelibId(station.getId()); } else if (qName.equals("updated")) { int updated = Integer.parseInt(current.toString()); infoStation.setUpdated(updated); infoStation.setStationVelibId(station.getId()); try { infoStationDao = DatabaseHelper.getInstance(context).getDao(InfoStation.class); QueryBuilder<InfoStation, ?> queryBuilder = infoStationDao.queryBuilder(); queryBuilder.where().eq(InfoStation.COLUMN_INFO_ID_STATION, station.getId()); PreparedQuery<InfoStation> preparedQuery = queryBuilder.prepare(); List<InfoStation> infoList = infoStationDao.query(preparedQuery); if (infoList.size() == 0) infoStationDao.create(infoStation); else if (infoStation.getUpdated() != updated) infoStationDao.update(infoStation); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /* * if(qName.equals("ticket")){ ticket = current.toString() != null; * } */ }
public ParserInfoStation(Context context, StationVelib station) { try { this.context = context; this.station = station; infoStation = new InfoStation(); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); xr.setContentHandler(this); xr.parse(new InputSource(new URL(URL_INFO + station.getNumber()).openStream())); } catch (Exception e) { e.printStackTrace(); } }