Je travaille sur un lecteur RSS très simple pour Android comme une expérience d'apprentissage. J'ai décidé d'utiliser le XmlPullParser pour analyser les flux car il est assez simple et a un niveau d'efficacité acceptable (pour mes besoins). J'obtiens une erreur en essayant d'analyser mon flux de test (rss.slashdot.org/slashdot/slashdot) que je n'arrive pas à résoudre malgré le fait de chercher des réponses sur le Web. L'erreur (de l'éclipse) est:Android Pull Parsing RSS flux problèmes
START_TAG <image>@2:1252 in [email protected]
START_TAG (empty) <{http://www.w3.org/2005/Atom}atom10:link rel='self' type='application/rss+xml' href='http://rss.slashdot.org/Slashdot/slashdot'>@2:1517 in [email protected]
DEBUG/JRSS(313): java.net.MalformedURLException: Protocol not found:
Le fichier en question est:
<image>
...
</image>
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://rss.slashdot.org/Slashdot/slashdot" />
<feedburner:info uri="slashdot/slashdot" />
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" />
...
si l'erreur semble se produire à la balise FeedBurner.
enfin, mon code est:
public class XmlHelper
{
private XmlPullParserFactory factory;
private XmlPullParser xpp;
private final int START_TAG = XmlPullParser.START_TAG;
// Debugging Tag
private final String TAG = "JRSS";
// for channels and items
private final String TITLE = "title";
private final String LINK = "link";
private final String DESCRIPTION = "description";
private final String PUBDATE = "pubDate";
// element keys for channel
private final String LANGUAGE = "language";
private final String IMAGE = "image";
private final String ITEM = "item";
// for items
private final String AUTHOR = "author";
// for images
private final String URL = "url";
private final String WIDTH = "width";
private final String HEIGHT = "height";
public XmlHelper(Context context)
{
try
{
factory = XmlPullParserFactory.newInstance();
}
catch (XmlPullParserException e)
{
Log.d(TAG, e.toString());
}
factory.setNamespaceAware(true);
}
public Channel addFeed(URL url) throws XmlPullParserException, IOException
{
Channel c = new Channel();
c.items = new ArrayList<Item>();
xpp = factory.newPullParser();
xpp.setInput(url.openStream(), null);
// move past rss element
xpp.nextTag();
// move past channel element
xpp.nextTag();
while(xpp.nextTag() == START_TAG)
{
Log.d(TAG, xpp.getPositionDescription());
if(xpp.getName().equals(TITLE))
c.title = xpp.nextText();
else if(xpp.getName().equals(LINK))
c.url = new URL(xpp.nextText());
else if(xpp.getName().equals(DESCRIPTION))
c.description = xpp.nextText();
else if(xpp.getName().equals(LANGUAGE))
c.language = xpp.nextText();
else if(xpp.getName().equals(ITEM))
{
Item i = parseItem(xpp);
c.items.add(i);
}
else if(xpp.getName().equals(IMAGE))
{
parseImage(xpp);
}
else
xpp.nextText();
}
return c;
}
public Item parseItem(XmlPullParser xpp) throws MalformedURLException, XmlPullParserException, IOException
{
Item i = new Item();
while(xpp.nextTag() == START_TAG)
{
// do nothing for now
xpp.nextText();
}
return i;
}
private void parseImage(XmlPullParser xpp) throws XmlPullParserException, IOException
{
// do nothing for now
while(xpp.nextTag() == START_TAG)
{
xpp.nextText();
}
}
Je ne sais pas vraiment s'il y a un moyen d'ignorer cela (car à ce stade, je ne me soucie pas de l'étiquette feedburner) ou si est une caractéristique de l'analyseur que je peux définir pour faire ce travail, ou si je vais à ce sujet dans le mauvais sens. Toute aide/conseil/orientation serait appréciée.