- private static List<Schoolnews> parseXML(InputStream in)
- throws XmlPullParserException, IOException {
- List<Schoolnews> snews = null;
- Schoolnews schoolnews = null;
- XmlPullParser pullParser = Xml.newPullParser();
- pullParser.setInput(in, "UTF-8");
- int event = pullParser.getEventType();
- while (event != XmlPullParser.END_DOCUMENT) {
- switch (event) {
- case XmlPullParser.START_DOCUMENT:
- snews = new ArrayList<Schoolnews>();
- break;
- case XmlPullParser.START_TAG:
- if ("Schoolnews".equals(pullParser.getName())) {
- int id = new Integer(pullParser.getAttributeValue(0));
- schoolnews = new Schoolnews();
- schoolnews.setId(id);
- }
- if ("title".equals(pullParser.getName())) {
- schoolnews.setTitle(pullParser.nextText());
- }
- if ("content".equals(pullParser.getName())) {
- schoolnews.setContent(pullParser.nextText());
- }
- if ("sharedate".equals(pullParser.getName())) {
- schoolnews.setShareDate(pullParser.nextText());
- }
- if ("shareperson".equals(pullParser.getName())) {
- schoolnews.setShareperson(pullParser.nextText());
- }
- if ("pictureuri".equals(pullParser.getName())) {
- schoolnews.setPictureuri(pullParser.nextText());
- }
- break;
- case XmlPullParser.END_TAG:
- if ("Schoolnews".equals(pullParser.getName())) {
- snews.add(schoolnews);
- schoolnews = null;
- }
- break;
- }
- event = pullParser.next();
- }
- return snews;
- }
- }
时间: 2024-10-13 06:47:40