Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val factory = XmlPullParserFactory.newInstance();
- factory.isNamespaceAware = true;
- val xpp = factory.newPullParser();
- xpp.setInput(StringReader(data));
- var currentQuizz : Quizz? = null;
- var currentQuestion : Int = 0;
- var currentTag : Tag = Tag.UNKNOWN;
- var eventType = xpp.eventType;
- while (eventType != XmlPullParser.END_DOCUMENT)
- {
- if (eventType == XmlPullParser.START_TAG)
- {
- if (xpp.name == "Quizz")
- {
- currentQuizz = Quizz(xpp.getAttributeValue(0), mutableListOf(), mutableListOf(), mutableListOf());
- currentQuestion = 0;
- currentTag = Tag.UNKNOWN;
- }
- else if (xpp.name == "Question")
- {
- currentTag = Tag.QUESTION;
- }
- else if (xpp.name == "Proposition")
- {
- currentTag = Tag.PROPOSITION;
- }
- else if (xpp.name == "Reponse")
- {
- currentQuizz!!.setAnswerFor(currentQuestion, xpp.getAttributeValue(0).trim().toInt() - 1);
- }
- }
- else if (eventType == XmlPullParser.END_TAG)
- {
- if (xpp.name == "Question")
- {
- currentQuestion++;
- }
- else if (xpp.name == "Quizz")
- {
- val sameNameID = findQuizzId(currentQuizz!!.getName());
- if (sameNameID != -1)
- {
- removeQuizz(m_quizzList[sameNameID]);
- }
- addQuizz(currentQuizz!!);
- }
- }
- else if (eventType == XmlPullParser.TEXT)
- {
- if (currentTag == Tag.QUESTION)
- {
- currentQuizz!!.addQuestion(xpp.text.trim());
- currentQuizz!!.getAnswerStringsFor(currentQuestion).removeAt(0);
- currentTag = Tag.UNKNOWN;
- }
- else if (currentTag == Tag.PROPOSITION)
- {
- currentQuizz!!.addAnswerFor(currentQuestion, xpp.text.trim());
- currentTag = Tag.UNKNOWN;
- }
- }
- eventType = xpp.next()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement