I’ve been using XmlPullParser to generate forms on an android application from a locally stored xml document.
XmlPullParser xpp = getResources().getXml(R.xml.calculator);
int eventType = xpp.getEventType();
and then I have the while loop that processes all the elements in the tree. However, because I keep using
eventType = xpp.next();
this is a Depth-first method when in fact I want a Breadth-first method of doing things (the user drills down the tree by asking questions). Most of the xml tutorials rely on DOM which I’ve heard is unreliable on android because of memory constraints. I would be very grateful for help.
The xml is in this form
<top>
<page>
<question>This is the first question</question>
<answer>
<text>Answer 1</text>
<page>
<question>If you choose Answer 1 you get asked this question</question>
<answer>
.
.
</answer>
<answer>
.
.
</answer>
</page>
</answer>
<answer>
<text>Answer 2</text>
.
.
.
</answer>
</page>
</top>
I hope that makes a little more sense than it did before. So in effect, given this tree, I want to generate screens (at run-time) that ask the user these questions and take their answers in. Depending on their answers, they get the next set of questions. Thanks for the really quick responses!!
It seems to me that breadfirst algorithm would be intuitively more efficient to get the first level nodes. However, this seems to be a very “human” approach. I can’t think of a way an xml parser could guess where a first level tag ends when it reads the start tag.
So, anyhow, your parser will have to read the whole file, stacking all nodes. Maybe stacking could be avoided but it seems like a peanut compared to actually rading the xml structure itself. So gains wouldn’t be huge.
Did you consider using a database and two tables with a one to many relation ?
It would both solve efficiency and the amount of data your app would be able to deal with.
Regards,
Stéphane