使用SAX解析器,获取属性值
问题描述:
我使用Android从Web解析XML。下面的代码显示了一个XML示例。我遇到的问题是我无法获取item标签的字符串值。当我使用name = attributes.getQName(i);
时,它输出名称,而不是属性的值。使用代替使用SAX解析器,获取属性值
<weatherdata>
<timetags>
<item name="date">
<value>20/04/2012</value>
<unit/>
<image/>
<class>dynamic</class>
<description>The current date</description>
</item>
答
尝试attributes.getValue(i)
方法
答
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if(localName.equalsIgnoreCase("item")){
//currentMessage.setMediaUrl(attributes.getValue(BaseFeedParser.Url));
String valueis=attributes.getValue("name")
}
super.startElement(uri, localName, qName, attributes);
}