Android的萨克斯不解析" DC:创造者和QUOT ;? [英] android sax not parsing "dc:creator"?

查看:188
本文介绍了Android的萨克斯不解析" DC:创造者和QUOT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望有人能提供一些指导 - 我一直在使用的Andr​​oid SAX解析器有几个饲料。现在,当我想分析包含以下项目:

Hope someone can provide some guidance - i've been using android sax parser with several feeds. Now when I want to parse an item that contains following:

<category>category</category>
<dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">creator</dc:creator>
<dc:date xmlns:dc="http://purl.org/dc/elements/1.1/">2011-10-13T07:00:15Z</dc:date>
<geo:lat>51.95271682739258</geo:lat>
<geo:long>-0.21096819639205933</geo:long>

我可以得到类别的标签,为他人的价值,但什么都没有。

I can get the value of "category" tag, but nothing for the others.

在code使用从如下 HTTP的例子:// WWW。 ibm.com/developerworks/opensource/library/x-android/ ,尤其片段来解析标签:

The code used follows examples from http://www.ibm.com/developerworks/opensource/library/x-android/, in particular snippet to parse the tags:

Element item = channel.getChild("item");

item.getChild("category").setEndTextElementListener(new EndTextElementListener() {
  public void end(String body) {
   Log.e("mydebug","cat>>"+body+"<");
  }
});
item.getChild("dc:creator").setEndTextElementListener(new EndTextElementListener() {
  public void end(String body) {
   Log.e("mydebug","creator>>"+body+"<");
  }
});

生成的输出:

10-13 14:13:12.763: ERROR/mydebug(609): cat>>category<
10-13 14:13:12.763: ERROR/mydebug(609): cat>>category2<

我使用的是以下内容:

I'm using the following:

import android.sax.Element;
import android.sax.EndElementListener;
import android.sax.EndTextElementListener;
import android.sax.RootElement;
import android.util.Log;
import android.util.Xml;

什么我失踪?
我唯一​​能猜到的是,:在标签给我的问题,但我找不到类似的问题的任何实例

Anything I'm missing? Only thing I can guess is that ":" in the tag is giving me problems, but I couldn't find any examples of similar issue.

阅读非常感谢。

推荐答案

在使用的startElement()和endElement()在你的DefaultHandler的方法,无论是本地名称和限定名值传递。确保你正在检查合格的名称之类的东西。DC:创作者,否则他们将不会匹配

When using the startElement() and endElement() methods in your DefaultHandler, both the local name and qualified name values are passed in. Make sure you're checking the qualified name for things like 'dc:creator' or else they won't match.

在这里看到官方文档:<一href=\"http://developer.android.com/reference/org/xml/sax/helpers/DefaultHandler.html#startElement%28java.lang.String,%20java.lang.String,%20java.lang.String,%20org.xml.sax.Attributes%29\" rel=\"nofollow\">http://developer.android.com/reference/org/xml/sax/helpers/DefaultHandler.html#startElement%28java.lang.String,%20java.lang.String,%20java.lang.String,%20org.xml.sax.Attributes%29

此外,您还可以考虑使用XML解析器拉,因为它的重量比SAX多一点光,可能更适合您的需要:的http://developer.android.com/reference/org/xmlpull/v1/XmlPullParserFactory.html

Also, you may consider using the XML Pull Parser as it's a bit more light weight than SAX and might be more appropriate for your needs: http://developer.android.com/reference/org/xmlpull/v1/XmlPullParserFactory.html

这篇关于Android的萨克斯不解析&QUOT; DC:创造者和QUOT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆