i've been trying to parse the xml and assign its data into listview. But, i face issue when doing it because i wanted to parse from specific tag. You will get it once you see my below xml file.
XML file :
<rss>
<channel>
<title>Website title</title>
<atom:link href="http://ift.tt/16DtRWQ" rel="self" type="application/rss+xml"/>
<link>http://ift.tt/1F8h4qS;
<description>Film updates</description>
<lastBuildDate>Wed, 04 Feb 2015 09:52:51 +0000</lastBuildDate>
<item>
<title>Title one</title>
<link>http://ift.tt/16DtT0X;
<pubDate>Wed, 04 Feb 2015 08:40:01 +0000</pubDate>
</item>
<item>
<title>Title two</title>
<link>http://ift.tt/16DtT0Z;
<pubDate>Wed, 04 Feb 2015 08:40:01 +0000</pubDate>
</item>
</channel>
</rss>
Xmlpullparser :
while (eventType != XmlPullParser.END_DOCUMENT) {
String tagname = xpp.getName();
if (tagname!=null)
{
if (xpp.getEventType() == XmlPullParser.START_TAG) {
if (tagname.equalsIgnoreCase("item"))
{
System.out.println("This is the item tag : " +tagname);
RSSItem rs = new RSSItem(); // beginning the feed
}
if (tagname.equalsIgnoreCase("title"))
{
System.out.println("This is title tag inside item : " +tagname);
rs.setTitle(xpp.getText());
}
} // end of start tag
} // end of if null
eventType = xpp.next();
} // end of while loop
Here, my parser gets each tag until the document is end. So what if the case, when the tag is title but outside of item tag? i.e
<rss>
<channel>
<title>Website title</title> --> Here one title tag which i dont want
<item>
<title>...</title> --> Title tag i want.
</item>
<item>
<title>...</title>
</item>
</channel>
</rss>
How should i start parsing from that item tag? or how should i skip those initial tags before item tag?
No comments:
Post a Comment