Click here to Skip to main content
15,885,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Folks,
I've been finding the right way to parse the following Xml file in my android and I can't make the decision. Please give me some advise. I got the following XML files which is going to display in my android app.

XML
<?xml version="1.0" encoding="utf-8"?>
<Survey>
  <NonRepeat type="11::NewXmlTest" group="SIN" languages="ENCNHITA" dateandtime="9/16/2014 9:12:00 AM" />
  <Repeat>
    <Number>1</Number>
    <Question>MyNameisWhat::MyNameisWhat chin::MyNameisWhat hin::MyNameisWhat ta</Question>
    <AnswerA>What::What chin::What hin::What ta</AnswerA>
    <AnswerB>How::How chin::How hin::How ta</AnswerB>
    <AnswerC>When::When chin::When hin::When ta</AnswerC>
    <AnswerD>Why::Why chin::Why hin::Why ta</AnswerD>
    <AnswerE>Which::Which chin::Which hin::Which ta</AnswerE>
  </Repeat>
  <Repeat>
    <Number>2</Number>
    <Question>Another Question ::Another Question 1::Another Question 2::Another Question 3</Question>
    <AnswerA>What::What chin::What hin::What ta</AnswerA>
    <AnswerB>How::How chin::How hin::How ta</AnswerB>
    <AnswerC>When::When chin::When hin::When ta</AnswerC>
    <AnswerD>Why::Why chin::Why hin::Why ta</AnswerD>
    <AnswerE>Which::Which chin::Which hin::Which ta</AnswerE>
  </Repeat>
  <Repeat>
    <Number>3</Number>
    <Question>Sick::Sick Oh::Sick Oh My::Sick Oh My God</Question>
    <AnswerA>What::What chin::What hin::What ta</AnswerA>
    <AnswerB>How::How chin::How hin::How ta</AnswerB>
    <AnswerC>When::When chin::When hin::When ta</AnswerC>
    <AnswerD>Why::Why chin::Why hin::Why ta</AnswerD>
    <AnswerE>Which::Which chin::Which hin::Which ta</AnswerE>
  </Repeat>
</Survey>


I got two distinct elements, nonrepeat & repeat. The purpose of nonrepeat is to give the information about the data in repeat element. I am building the constructor for android using XmlPullParser. So far, I retreat nonrepeat data in String format and repeat data in arrayadapter. In the end, I can display them in listview without any changes. But I want to make it clean and neat for future improvement following this example.
So my question is
How do I create the constructor class to store repeat and nonrepeat data since one element need to parse once and the other element have to store in array?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900