从基于xmlns的元素解析SAX在Android中的元素
问题描述:
我想解析这xml file,但我找不到解析url属性<media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/41447000/jpg/_41447190_exomars66esa.jpg"/>
元素。我用下面的方法startElement
尝试了我的处理程序类从基于xmlns的元素解析SAX在Android中的元素
public void startElement(String Uri, String localName, String qName,
Attributes atts) throws SAXException {
if (localName.equals("channel")) {
this.in_channel = true;
}else if (localName.equals("item")) {
this.in_item = true;
}else if (localName.equals("title")) {
this.in_title = true;
}else if (localName.equals("media:thumbnail")) {
String attrValue = atts.getValue("url");
item.setLink(attrValue);
}
}
我也试过if (localName.equals("media")
,但没有奏效
我可以分析一个元素这样<link url="http://achdre.freehostia.com/example.xml"/>
,但不是我张贴以上。在此先感谢
答
您需要使用qName。
从doc:
的localName - 本地名称(不带前缀),如果未执行名称空间处理空字符串。
qName - 限定名称(带前缀)或空字符串(如果限定名称不可用)。
本地名称基本上剥离名称空间,所以如果你想要,你也可以做'缩略图',这也会匹配。
非常感谢,这工作得很好:) – pmantz 2011-03-09 12:01:36
@ demian83如果你写**缩略图**,而不是'(localName.equals(“media:thumbnail”))',它会工作。 – ozmank 2011-11-14 08:14:50