Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.67 KB | None | 0 0
  1. val factory = XmlPullParserFactory.newInstance();
  2.             factory.isNamespaceAware = true;
  3.             val xpp = factory.newPullParser();
  4.  
  5.             xpp.setInput(StringReader(data));
  6.  
  7.             var currentQuizz : Quizz? = null;
  8.             var currentQuestion : Int = 0;
  9.             var currentTag : Tag = Tag.UNKNOWN;
  10.  
  11.             var eventType = xpp.eventType;
  12.             while (eventType != XmlPullParser.END_DOCUMENT)
  13.             {
  14.                 if (eventType == XmlPullParser.START_TAG)
  15.                 {
  16.                     if (xpp.name == "Quizz")
  17.                     {
  18.                         currentQuizz = Quizz(xpp.getAttributeValue(0), mutableListOf(), mutableListOf(), mutableListOf());
  19.                         currentQuestion = 0;
  20.                         currentTag = Tag.UNKNOWN;
  21.                     }
  22.                     else if (xpp.name == "Question")
  23.                     {
  24.                         currentTag = Tag.QUESTION;
  25.                     }
  26.                     else if (xpp.name == "Proposition")
  27.                     {
  28.                         currentTag = Tag.PROPOSITION;
  29.                     }
  30.                     else if (xpp.name == "Reponse")
  31.                     {
  32.                         currentQuizz!!.setAnswerFor(currentQuestion, xpp.getAttributeValue(0).trim().toInt() - 1);
  33.                     }
  34.                 }
  35.                 else if (eventType == XmlPullParser.END_TAG)
  36.                 {
  37.                     if (xpp.name == "Question")
  38.                     {
  39.                         currentQuestion++;
  40.                     }
  41.                     else if (xpp.name == "Quizz")
  42.                     {
  43.                         val sameNameID = findQuizzId(currentQuizz!!.getName());
  44.  
  45.                         if (sameNameID != -1)
  46.                         {
  47.                             removeQuizz(m_quizzList[sameNameID]);
  48.                         }
  49.  
  50.                         addQuizz(currentQuizz!!);
  51.                     }
  52.                 }
  53.                 else if (eventType == XmlPullParser.TEXT)
  54.                 {
  55.                     if (currentTag == Tag.QUESTION)
  56.                     {
  57.                         currentQuizz!!.addQuestion(xpp.text.trim());
  58.                         currentQuizz!!.getAnswerStringsFor(currentQuestion).removeAt(0);
  59.                         currentTag = Tag.UNKNOWN;
  60.                     }
  61.                     else if (currentTag == Tag.PROPOSITION)
  62.                     {
  63.                         currentQuizz!!.addAnswerFor(currentQuestion, xpp.text.trim());
  64.                         currentTag = Tag.UNKNOWN;
  65.                     }
  66.                 }
  67.                 eventType = xpp.next()
  68.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement