使用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); 

attributes.getQName(i); 

因为doc说:

getQName返回属性的限定(前缀)名。

的getValue通过限定(加前缀的)名称查找属性的值。

看到this例如用于获取属性名称和值

尝试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); 
}