Android解析微博小尾巴
/** * 格式化微博来源小尾巴 * * @param sourceString * @return */ public static String formatWeiboSource(String sourceString) { ByteArrayInputStream bais = null; try { if (sourceString != null && !sourceString.trim().equals("")) { bais = new ByteArrayInputStream(sourceString.getBytes()); XmlPullParser parser = Xml.newPullParser(); try { parser.setInput(bais, "UTF-8"); int eventType = parser.getEventType(); int i=0; while (eventType != XmlPullParser.END_DOCUMENT) { Log.i("test", "循环次数"+i++); switch (eventType) { case XmlPullParser.START_DOCUMENT:// 文档开始事件,可以进行数据初始化处理 break; case XmlPullParser.START_TAG:// 开始元素事件 String name = parser.getName(); if (name.equalsIgnoreCase("a")) { String resultString = parser.nextText(); Log.i("test", "小尾巴:"+resultString); return resultString; } break; case XmlPullParser.END_TAG: break; default: break; } eventType = parser.next(); } bais.close(); } catch (Exception e) { e.printStackTrace(); // TODO: handle exception } } } catch (Exception e) { // TODO: handle exception e.printStackTrace(); return ""; } return ""; }