Android sax with rdf

情到浓时终转凉″ 提交于 2019-12-25 04:52:03

问题


i try to parse an rdf file using android.sax and android.utils.Xml methods. My parser ouputs nothing and don't send any exception.

RDF file:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss1full.xsl"?>
<?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?>
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns="http://purl.org/rss/1.0/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
   <channel rdf:about="http://www.olympique-et-lyonnais.com/">
     <title>OL Blog | Olympique et Lyonnais</title>
     <description />
     <link>http://www.olympique-et-lyonnais.com/</link>
     <dc:language>fr</dc:language>
     <dc:creator />
     <dc:rights />
     <dc:date>2010-06-01T23:23:50+02:00</dc:date>
     <admin:generatorAgent rdf:resource="http://www.dotclear.net/" />

     <sy:updatePeriod>daily</sy:updatePeriod>
     <sy:updateFrequency>1</sy:updateFrequency>
     <sy:updateBase>2010-06-01T23:23:50+02:00</sy:updateBase>

     <items>
     ...
     </items>
   <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rdf+xml" href="http://feeds.feedburner.com/oetl" /><feedburner:info uri="oetl" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" />
   </channel>

   <item rdf:about="http://www.olympique-et-lyonnais.com/ligue-1/la-toul-ce-tlier,4513.html">
     <title>La Toul, ce tôlier</title>
     <link>http://feedproxy.google.com/~r/oetl/~3/RycUlTDp3eY/la-toul-ce-tlier,4513.html</link>
     <dc:date>2010-06-01T23:23:50+02:00</dc:date>
     <dc:language>fr</dc:language>
     <dc:creator>Aurelien</dc:creator>
     <dc:subject>Ligue 1</dc:subject>
     <description>Décidément très bavard ces derniers temps notamment dans la presse, Jean-Michel Aulas n'a pas seulement livré le plan de recrutement de l'OL, il a aussi parlé de certains joueurs actuellement en place au club et de leur avenir. Le président est notamment...</description>
     <content:encoded><![CDATA[D&eacute;cid&eacute;ment tr&egrave;s bavard ces derniers temps notamment dans la presse, Jean-Michel Aulas n'a pas seulement livr&eacute; le plan de recrutement de l'OL, il a aussi parl&eacute; de certains joueurs actuellement en place au club et de leur avenir. Le pr&eacute;sident est notamment...<img src="http://feeds.feedburner.com/~r/oetl/~4/RycUlTDp3eY" height="1" width="1"/>]]></content:encoded>
   <feedburner:origLink>http://www.olympique-et-lyonnais.com/ligue-1/la-toul-ce-tlier,4513.html</feedburner:origLink></item>
...
</rdf:RDF>

my parser:

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 = "";

   try{
    RootElement root;
    Element itemlist;
    Element item;
    String namespace;
    if(feedsTypes[i].equals("RDF")){
     Log.i(TAG, "RDF feed");
     namespace = RDF_NAMESPACE;
     root = new RootElement(RDF_NAMESPACE, feedsTypes[i]);
     item = root.getChild(RDF_NAMESPACE, ITEM);
    }
    else{
     Log.i(TAG, "RSS feed");
     namespace = RSS_NAMESPACE;
     root = new RootElement(RSS_NAMESPACE, feedsTypes[i]);
     itemlist = root.getChild(RSS_NAMESPACE, CHANNEL);
     item = itemlist.getChild(RSS_NAMESPACE, ITEM);
    }
    item.setStartElementListener(new StartElementListener(){
     @Override
     public void start(Attributes attributes) {
      Log.i(TAG, "item///");
     }
    });
    item.setEndElementListener(new EndElementListener(){
     public void end() {
      Log.i(TAG, "///item");
      messages.add(currentMessage.copy());
     }
    });
    item.getChild(namespace, TITLE).setEndTextElementListener(new EndTextElementListener(){
     public void end(String body) {
      Log.i(TAG, body);
      currentMessage.setTitle(body);
     }
    });
    Xml.parse(this.getInputStream(), Xml.Encoding.UTF_8, root.getContentHandler());
   }
   catch(Exception e){
    Log.w(TAG, e.getMessage());
   }

Is there someone who can tell me what i'm doing wrong ?


回答1:


<rdf:RDF ...> <item>...</item> </rdf:RDF>

Item element is not in rdf: namespace, relevant command should read: item = root.getChild("", ITEM);




回答2:


Your code looks strange, why you do not use a normal SaxParser? http://www.mkyong.com/java/how-to-read-xml-file-in-java-sax-parser/




回答3:


why not use any common feed java parser?

BTW, the RSS_NAMESPACE variable in your code doesn't fit with the namespace used in the file: default namespace doesn't mean empty namespace.



来源:https://stackoverflow.com/questions/2966016/android-sax-with-rdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!