Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

android - How to display data in a ListView once you parse the XML with nested tag?

I have the XML file which is like this:

<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>

Now i want to parse this XML file and Display it like this in ListView :::

Consider filename tag as Status ::

Status 1:

        Comment 1
        Comment 2   
        Comment 3 
        Comment 4

Status 2:

        Comment 1
        Comment 2   
        Comment 3 

Suppose the first activity has 4 comment as a nested tag and second activity has the 3 comment in his comment tag.

How to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try using SAX Parser which is provided by Android.

Here's a good example how can u parse an XML file using SAX Parser method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...