private static Question parseQuestion(Element question) { Question questionObj = new Question(); questionObj.setQuestionText( question.getElementsByTagName("text").item(0).getChildNodes().item(0).getNodeValue()); Element answerChoices = (Element) question.getElementsByTagName("answerchoices").item(0); parseChoices(answerChoices, questionObj); String answerChoice = question.getElementsByTagName("answer").item(0).getChildNodes().item(0).getNodeValue(); if (answerChoice != null) { questionObj.setAnswerCode(Integer.valueOf(answerChoice) - 1); } return questionObj; }
private static void parseChoices(Element answerChoices, Question questionObj) { String[] choices = new String[4]; questionObj.setChoices(choices); choices[0] = answerChoices.getElementsByTagName("a").item(0).getChildNodes().item(0).getNodeValue(); choices[1] = answerChoices.getElementsByTagName("b").item(0).getChildNodes().item(0).getNodeValue(); choices[2] = answerChoices.getElementsByTagName("c").item(0).getChildNodes().item(0).getNodeValue(); choices[3] = answerChoices.getElementsByTagName("d").item(0).getChildNodes().item(0).getNodeValue(); }