Back to project page SELP2013.
The source code is released under:
License ======= This work is licensed under the BSD 2-clause license as follows. # BSD 2-clause license Copyright (c) 2013, Sky Welch All rights reserved. Redistribution and use in source and ...
If you think the Android project SELP2013 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package uk.co.skywelch.selp2013; //from w ww.j a v a 2 s.c o m import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import android.util.Xml; public class CoursesXmlParser { private static final String ns = null; public ArrayList<Course> parse(InputStream in) throws XmlPullParserException, IOException { try { XmlPullParser parser = Xml.newPullParser(); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); parser.setInput(in, null); parser.nextTag(); return readFeed(parser); } finally { in.close(); } } private ArrayList<Course> readFeed(XmlPullParser parser) throws XmlPullParserException, IOException { ArrayList<Course> entries = new ArrayList<Course>(); parser.require(XmlPullParser.START_TAG, ns, "list"); while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) { continue; } String name = parser.getName(); if (name.equals("course")) { entries.add(readEntry(parser)); } else { XMLUtilities.skip(parser); } } return entries; } // Parses the contents of a course private Course readEntry(XmlPullParser parser) throws XmlPullParserException, IOException { parser.require(XmlPullParser.START_TAG, ns, "course"); String url = null; String name = null; String drps = null; String euclid = null; String acronym = null; Boolean ai = null; Boolean cg = null; Boolean cs = null; Boolean se = null; Integer level = null; Integer points = null; Integer year = null; String deliveryperiod = null; String lecturer = null; // Run through each tag and update our Course with values if they exist while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) { continue; } String tag = parser.getName(); if (tag.equals("url")) { url = XMLUtilities.readString(parser, ns, "url"); } else if (tag.equals("name")) { name = XMLUtilities.readString(parser, ns, "name"); } else if (tag.equals("drps")) { drps = XMLUtilities.readString(parser, ns, "drps"); } else if (tag.equals("euclid")) { euclid = XMLUtilities.readString(parser, ns, "euclid"); } else if (tag.equals("acronym")) { acronym = XMLUtilities.readString(parser, ns, "acronym"); } else if (tag.equals("ai")) { ai = XMLUtilities.readString(parser, ns, "ai").equals("AI"); } else if (tag.equals("cg")) { cg = XMLUtilities.readString(parser, ns, "cg").equals("CG"); } else if (tag.equals("cs")) { cs = XMLUtilities.readString(parser, ns, "cs").equals("CS"); } else if (tag.equals("se")) { se = XMLUtilities.readString(parser, ns, "se").equals("SE"); } else if (tag.equals("level")) { level = XMLUtilities.readInteger(parser, ns, "level"); } else if (tag.equals("points")) { points = XMLUtilities.readInteger(parser, ns, "points"); } else if (tag.equals("year")) { year = XMLUtilities.readInteger(parser, ns, "year"); } else if (tag.equals("deliveryperiod")) { deliveryperiod = XMLUtilities.readString(parser, ns, "deliveryperiod"); } else if (tag.equals("lecturer")) { lecturer = XMLUtilities.readString(parser, ns, "lecturer"); } else { XMLUtilities.skip(parser); } } return new Course(url, name, drps, euclid, acronym, ai, cg, cs, se, level, points, year, deliveryperiod, lecturer); } }