
<img src='hamster.jpg'/><p>Hello</p><ul><li>...</li><li>...</li></ul>
void startElement(String uri, String localName, String qName, Attributes attributes)void endElement(String uri, String localName, String qName)void characters(char[] ch, int start, int length)characters can be called multiple times. Use my BasicHandler convenience class.BasicHandler. Add fields for whatever you want to collect, or make inner class in the object that you are building.startElementendElementpublic class Question implements Serializable {
private String text;
private List<String> choices = new ArrayList<String>();
private int correctChoice;
public void readFromXml(InputStream in) throws IOException {
class QuestionHandler extends BasicHandler {
@Override
public void startElement(String uri, String localName,
String qName, Attributes attributes) throws SAXException {
super.startElement(uri, localName, qName, attributes);
if ("true".equals(attributes.getValue("value")))
correctChoice = choices.size();
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
if (qName.equals("text")) text = lastString();
else if (qName.equals("choice")) choices.add(lastString());
}
}
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
parser.parse(in, new QuestionHandler());
} catch (Exception ex) {
IOException ioEx = new IOException(ex.getMessage());
ioEx.initCause(ex);
throw ioEx;
}
}
...
}
Put your answer into Piazza.
What is NOT true about RSS parser code example in Android Recipes Section 3.8?
BasicHandler convenience class, the startElement method would have been shorter.channel element must be handled in the startElement method.title element must be handled in the endElement method.inItem flag is necessary.What is NOT true about the XML pull parser implementation of the RSS parser code?
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
} is necessary.


BasicHandler to your project.readFromXml method from the slide to the Question class.doInBackground. What is your code? (You did this in lab 3 and your homework.)readFromXml more closely. Why does the startElement method call super.startElement but the endElement doesn't?startElement method look at qName?if condition in startElement
attributes.getValue("value").equals("true") Try it out if you don't know.