如何在 Android 应用程序中解析 XML 文件
我正在尝试解析一个 XML 文件,如下所示
<Subject>
<chapter>
<Question>abc</Question>
<answer>avksn</answer>
</chapter>
<chapter>
<Question>def</Question>
<answer>avksn</answer>
</chapter>
<chapter>
<Question>ccsv</Question>
<answer>avksn</answer>
</chapter>
</Subject>
,我可以计算章节数。章节数等于问题和答案的数量。我还在我的布局中放置了一个名为“确定”的按钮。
现在我想显示第一个问题,单击“确定”后我想显示第二个问题,直到结束。当我到达最后一个问题时,我想转向新的活动。
如何执行此操作,请帮助我
I am trying to parse an XML file as below
<Subject>
<chapter>
<Question>abc</Question>
<answer>avksn</answer>
</chapter>
<chapter>
<Question>def</Question>
<answer>avksn</answer>
</chapter>
<chapter>
<Question>ccsv</Question>
<answer>avksn</answer>
</chapter>
</Subject>
in this i am able to count the number of chapter. the number of chapter is equal to number of question and answer. i have also placed a button named as ok in my layout.
now i want to display the first question and after clicking ok i want to display the second question and it goes till the end. When i reached the last question i want to move to a new activity.
how to perform this, pls help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 xml 读入 InputStream 然后:
然后您可以使用 doc,如下所示:
Read the xml into a InputStream and then:
Then you can use doc like:
将 XML 读入文档( v = xml 字符串)
然后获取元素,如下所示:
如何使用:
Read the XML into a document ( v = the xml string )
Then get the element like so:
How to use: