VTD-XML reading gives no results

46 views Asked by At

I am trying to read a RSS content using VTD-XML. Below is a sample of RSS.

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
   <?xml-stylesheet type="text/xsl" href="rss.xsl"?>
   <channel>
      <title>MyRSS</title>
      <atom:link href="http://www.example.com/rss.php" rel="self" type="application/rss+xml" />
      <link>http://www.example.com/rss.php</link>
      <description>MyRSS</description>
      <language>en-us</language>
      <pubDate>Tue, 22 May 2018 13:15:15 +0530</pubDate>
      <item>
         <title>Title 1</title>
         <pubDate>Tue, 22 May 2018 13:14:40 +0530</pubDate>
         <link>http://www.example.com/news.php?nid=47610</link>
         <guid>http://www.example.com/news.php?nid=47610</guid>
         <description>bla bla bla</description>
      </item>
</channel>
</rss>

Anyway as you know, some RSS feeds can contain more styling info etc. However in every RSS, the <channel> and <item> will be common, at least for the ones I need to use.

I tried VTD XML to read this as quickly as possible. Below is the code.

VTDGen vg = new VTDGen();
        if (vg.parseHttpUrl(appDataBean.getUrl(), true)) {
            VTDNav vn = vg.getNav();
            AutoPilot ap = new AutoPilot(vn);
            ap.selectXPath("/channel/item");
            int result = -1;

            while ((result = ap.evalXPath()) != -1) {
                if (vn.matchElement("item")) {
                    do {
                        //do something with the contnets in the item node
                        Log.d("VTD", vn.toString(vn.getText()));
                    } while (vn.toElement(VTDNav.NEXT_SIBLING));
                }
            }
        }

Unfortunately this did not print anything. What am I doing wrong here? Also non of the RSS feeds are very big, so I need to read them in couple of miliseconds. This code is on Android.

0

There are 0 answers