/** * Constructor. Builds the shared objects used for parsing. * * @throws XmlPullParserException if error creating parser */ public PullHandler() throws XmlPullParserException { XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); m_parser = factory.newPullParser(); m_startTag = factory.newStartTag(); m_endTag = factory.newEndTag(); m_buffer = new StringBuffer(); }
public static void main(String[] args) { try { MysqlBggRepository rep = new MysqlBggRepository(); try { for (BggGame game : rep.getCorrelatedGamesList()) { URL url = new URL( "http://www.boardgamegeek.com/xmlapi/boardgame/" + game.getBggId() + "?stats=1"); InputStream is = url.openStream(); XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser(); parser.setInput(is, "UTF8"); int result = parser.getEventType(); boolean ratingFound = false; while (result != XmlPullParser.END_DOCUMENT) { if (result == XmlPullParser.START_TAG) { if ("average".equals(parser.getName())) { Float rating = Float.parseFloat(parser.nextText()); game.setAvgBggRating(rating); rep.setAvgBggRating(game, rating); if (ratingFound) { throw new RuntimeException("Already found one rating"); } else { System.out.println( "Set (" + game.getBggId() + ") " + game.getName() + " to: " + rating); ratingFound = true; } } } result = parser.next(); } } } finally { try { rep.close(); } catch (Exception e) { } } } catch (Exception e) { e.printStackTrace(); } }
@Override public Tweets read(InputStream anInputStream) throws Exception { XmlPullParser _p = f.newPullParser(); _p.setInput(anInputStream, "utf-8"); return parse(_p); }
public PullParserTweetsReader() throws Exception { dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); f = XmlPullParserFactory.newInstance(); f.setNamespaceAware(true); }