如何在使用嵌套标签解析XML时在ListView中显示数据?

问题描述:

我有XML文件,该文件是这样的:如何在使用嵌套标签解析XML时在ListView中显示数据?

<activities> 
<activity> 
    <filename>http://www.someurl.com/documentSetting/members/0/701/66/videos/521/521.mp4</filename> 
    <thumbnail>http://www.someurl.com/documentSetting/members/0/701/66/videos/521/521_120x90.jpg</thumbnail> 
    <id>521</id> 
    <is_private>0</is_private> 
    <comments> 
     <comment> 
      <id>111</id> 
      <body>Good video</body> 
      <member_id>oo7</member_id> 
      <profile_image>http://www.someurl.com/images/avatar/default_male_qlone.png</profile_image> 
     </comment> 
     <comment> 
      <id>222</id> 
      <body>nice video</body> 
      <member_id>123</member_id> 
      <profile_image>http://www.someurl.com/images/avatar/default_male_qlone.png</profile_image> 
     </comment> 
     <comment> 
      <id>333</id> 
      <body>gotcha!!!</body> 
      <member_id>11</member_id> 
      <profile_image>http://www.someurl.com/images/avatar/default_male_qlone.png</profile_image> 
     </comment> 
</activity> 

<activity> 
    <filename>http://www.someurl.com/documentSetting/members/0/701/66/videos/521/521.mp4</filename> 
    <thumbnail>http://www.someurl.com/documentSetting/members/0/701/66/videos/521/521_120x90.jpg</thumbnail> 
    <id>522</id> 
    <is_private>0</is_private> 
    <comments> 
     <comment> 
      <id>101</id> 
      <body>aaa</body> 
      <member_id>oo7</member_id> 
      <profile_image>http://www.someurl.com/images/avatar/default_male_qlone.png</profile_image> 
     </comment> 
     <comment> 
      <id>222</id> 
      <body>bbb</body> 
      <member_id>123</member_id> 
      <profile_image>http://www.someurl.com/images/avatar/default_male_qlone.png</profile_image> 
     </comment> 
     <comment> 
      <id>333</id> 
      <body>ccc</body> 
      <member_id>11</member_id> 
      <profile_image>http://www.someurl.com/images/avatar/default_male_qlone.png</profile_image> 
     </comment> 
</activity> 

现在我要分析此XML文件并在ListView控件:::

考虑文件名标签作为状态显示它像这样::

状态1:

 Comment 1 
     Comment 2 
     Comment 3 
     Comment 4 

状态2:

 Comment 1 
     Comment 2 
     Comment 3 

假设第一活动具有作为嵌套的标签4的评论和第二活动在他的注释标记的3注释。

如何做到这一点?

+0

Im相当肯定这之前已经 [http://*.com/questions/4488915/how-data-can-be-parsing-in-xml-parsing-and-data-回答显示功能于列表视图合机器人] [1] [1]:http://*.com/questions/4488915/how-data-can-be-parsing-in-xml-parsing和数据显示在列表中查看在Android – Kickaha

+0

我看着这个link.but如何显示在列表视图中按我的要求,因为我在我的问题中提到? plz很快帮助我! – user1221162

+0

ArrayAdapter如上所述 – Kickaha

尝试使用由Android提供的SAX解析器。

这是一个很好的example 如何使用SAX Parser方法解析XML文件。

+0

我完成解析,但我无法显示它accroding我的要求在listview这是问题。 – user1221162