There was a question of how to properly parse the below part of the XML file using JAXB:
<question> <category>filled</category> <qtype>Описание типа вопроса</qtype> <weight>0</weight> <questionbody><![CDATA[Тело вопроса]]></questionbody> <answers> <answer type="true"> <name><![CDATA[1 вариант ответа]]></name> </answer> <answer type="true"> <name><![CDATA[2 вариант ответа]]></name> </answer> </answers> </question> <question> <category>single</category> <qtype>Описание типа вопроса</qtype> <weight>0</weight> <questionbody><![CDATA[Тело вопроса]]></questionbody> <answers> <answer id="1" type="false"> <name><![CDATA[Не верный]]></name> </answer> <answer id="2" type="true"> <name><![CDATA[верный]]></name> </answer> <answer id="3" type="false"> <name><![CDATA[не верный]]></name> </answer> </answers> </question> <question> <category>multiply</category> <qtype>Описание типа вопроса</qtype> <weight>0</weight> <questionbody><![CDATA[Тело вопроса]]></questionbody> <answers> <answer id="1" type="true"> <name><![CDATA[Верный]]></name> </answer> <answer id="2" type="true"> <name><![CDATA[Верный]]></name> </answer> <answer id="3" type="false"> <name><![CDATA[Не верный]]></name> </answer> </answers> </question> <question> <category>comparison</category> <qtype>Описание типа вопроса</qtype> <weight>10</weight> <questionbody><![CDATA[Тело вопроса]]></questionbody> <answers> <answer> <answbody id="1141"><![CDATA[1]]></answbody> <name id="1141"><![CDATA[1]]></name> </answer> <answer> <answbody id="2141"><![CDATA[2]]></answbody> <name id="2141"><![CDATA[2]]></name> </answer> </answers> </question> <question> <category>sort</category> <qtype>Описание типа вопроса</qtype> <weight>10</weight> <questionbody><![CDATA[Тело вопроса]]></questionbody> <answers> <answer type="true" order="1"> <name><![CDATA[1]]></name> </answer> <answer type="true" order="2"> <name><![CDATA[2]]></name> </answer> </answers> </question> Here's what I got:
public class QuestionWrapper { @XmlElement(name = "category") private String category; @XmlElement(name = "qtype") private String qtype; @XmlElement(name = "weight") private int weight; @XmlElement(name = "questionbody") private String questionbody; @XmlElement(name = "answer") @XmlElementWrapper(name = "answers") List<AnswerWrapper> answer; public String getCategory() { return category; } public String getQtype() { return qtype; } public int getWeight() { return weight; } public String getQuestionbody() { return questionbody; } public List<AnswerWrapper> getAnswer() { return answer; } } Question: I did not understand how to correctly parse the answer.
It turns out with different structure.
Changing the xml structure is no longer possible.