Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid SAX Parser for RDF feed
    text
    copied!<p>I'm completely stuck for a couple of days on trying to parse an RDF feed (newbie on Android parsers). In spite of using:</p> <pre><code>Element item = root.getChild("", ITEM); </code></pre> <p>since my items come from the root instead of CHANNEL, as appointed <a href="https://stackoverflow.com/questions/2966016/android-sax-with-rdf">here</a>. Anyway, I'm only retrieving 0 messages</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns="http://purl.org/rss/1.0/"&gt; &lt;channel rdf:about="http://..."&gt; &lt;title&gt;Notícies&lt;/title&gt; &lt;link&gt;...&lt;/link&gt; &lt;description&gt;&lt;/description&gt; &lt;syn:updatePeriod&gt;daily&lt;/syn:updatePeriod&gt; &lt;syn:updateFrequency&gt;1&lt;/syn:updateFrequency&gt; &lt;syn:updateBase&gt;2009-08-25T16:01:24Z&lt;/syn:updateBase&gt; &lt;image rdf:resource="..."/&gt; &lt;items&gt; &lt;rdf:Seq&gt; &lt;rdf:li rdf:resource="..."/&gt; &lt;rdf:li rdf:resource="..."/&gt; &lt;/rdf:Seq&gt; &lt;/items&gt; &lt;/channel&gt; &lt;item rdf:about="..."&gt; &lt;title&gt;...&lt;/title&gt; &lt;link&gt;....&lt;/link&gt; &lt;description&gt;...&lt;/description&gt; &lt;dc:publisher&gt;No publisher&lt;/dc:publisher&gt; &lt;dc:creator&gt;administrador&lt;/dc:creator&gt; &lt;dc:rights&gt;&lt;/dc:rights&gt; &lt;dc:date&gt;2013-03-22T16:18:36Z&lt;/dc:date&gt; &lt;dc:type&gt;Noticia&lt;/dc:type&gt; &lt;/item&gt; &lt;item rdf:about="..."&gt; &lt;title&gt;...&lt;/title&gt; &lt;link&gt;....&lt;/link&gt; &lt;description&gt;...&lt;/description&gt; &lt;dc:publisher&gt;No publisher&lt;/dc:publisher&gt; &lt;dc:creator&gt;administrador&lt;/dc:creator&gt; &lt;dc:rights&gt;&lt;/dc:rights&gt; &lt;dc:date&gt;2013-03-22T16:18:36Z&lt;/dc:date&gt; &lt;dc:type&gt;Noticia&lt;/dc:type&gt; &lt;/item&gt; &lt;item rdf:about="..."&gt; &lt;title&gt;...&lt;/title&gt; &lt;link&gt;....&lt;/link&gt; &lt;description&gt;...&lt;/description&gt; &lt;dc:publisher&gt;No publisher&lt;/dc:publisher&gt; &lt;dc:creator&gt;administrador&lt;/dc:creator&gt; &lt;dc:rights&gt;&lt;/dc:rights&gt; &lt;dc:date&gt;2013-03-22T16:18:36Z&lt;/dc:date&gt; &lt;dc:type&gt;Noticia&lt;/dc:type&gt; &lt;/item&gt; ... &lt;/rdf:RDF&gt; </code></pre> <p>Using my SAX Parser as follows:</p> <pre><code>public class AndroidSaxFeedParser extends BaseFeedParser { static final String RDF_NAMESPACE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; static final String ATOM_NAMESPACE = "http://www.w3.org/2005/Atom"; static final String RSS_NAMESPACE = ""; static final String RSS = "RDF"; public AndroidSaxFeedParser(String feedUrl) { super(feedUrl); } public List&lt;Message&gt; parse() { final Message currentMessage = new Message(); //RootElement root = new RootElement(RSS); RootElement root = new RootElement(RDF_NAMESPACE, RSS); final List&lt;Message&gt; messages = new ArrayList&lt;Message&gt;(); //Element channel = root.getChild(CHANNEL); //Element channel = root.getChild(RDF_NAMESPACE, CHANNEL); Log.e("Valor Root", root.toString()); Element item = root.getChild("", ITEM); //Element item = channel.getChild(RDF_NAMESPACE,ITEM); item.setEndElementListener(new EndElementListener(){ public void end() { messages.add(currentMessage.copy()); } }); item.getChild(TITLE).setEndTextElementListener(new EndTextElementListener(){ public void end(String body) { currentMessage.setTitle(body); } }); item.getChild(LINK).setEndTextElementListener(new EndTextElementListener(){ public void end(String body) { currentMessage.setLink(body); } }); item.getChild(DESCRIPTION).setEndTextElementListener(new EndTextElementListener(){ public void end(String body) { currentMessage.setDescription(body); } }); item.getChild(PUB_DATE).setEndTextElementListener(new EndTextElementListener(){ public void end(String body) { currentMessage.setDate(body); } }); try { Xml.parse(this.getInputStream(), Xml.Encoding.UTF_8, root.getContentHandler()); } catch (Exception e) { throw new RuntimeException(e); } return messages; } } </code></pre> <p>I've tried</p> <blockquote> <p>Element item = root.getChild("RDF_NAMESPACE", ITEM); Element item = root.getChild("", ITEM); Element item = root.getChild(ITEM);</p> </blockquote> <p>But those 3 options return 0 messages. Any help would be really much appreciated. Many thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload