使用SAX Parser,获取属性的值 [英] With SAX Parser, get an attribute's value
本文介绍了使用SAX Parser,获取属性的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Android从网络解析XML。下面的代码显示了XML的示例。我遇到的问题是我无法获取item标签的字符串值。当我使用 name = attributes.getQName(i);
时,它输出名称,而不是属性的值。
I am parsing XML from the web using Android. The code below shows a sample of the XML. The problem I'm having is I can't get the string value of the item tag. When I use name = attributes.getQName(i);
it outputs the name, not the value of the attribute.
<weatherdata>
<timetags>
<item name="date">
<value>20/04/2012</value>
<unit/>
<image/>
<class>dynamic</class>
<description>The current date</description>
</item>
推荐答案
使用
attributes.getValue(i);
而不是
attributes.getQName(i);
因为 doc 说:
getQName :返回属性的限定(加前缀)名称。
getValue :通过限定查找属性的值(前缀) )名称。
参见 this 获取属性名称和值的示例
see this example for getting attribute name and value
这篇关于使用SAX Parser,获取属性的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文