使用SAX Parser,获取属性的值

car*_*y88 15 java xml android xml-attribute saxparser

我正在使用Android从Web解析XML.下面的代码显示了XML的示例.我遇到的问题是我无法获取item标签的字符串值.当我使用name = attributes.getQName(i);它时输出名称,而不是属性的值.

<weatherdata>
 <timetags>
  <item name="date">
   <value>20/04/2012</value>
   <unit/>
   <image/>
   <class>dynamic</class>
   <description>The current date</description>
  </item>
Run Code Online (Sandbox Code Playgroud)

ρяσ*_*я K 17

使用

attributes.getValue(i);
Run Code Online (Sandbox Code Playgroud)

代替

attributes.getQName(i);
Run Code Online (Sandbox Code Playgroud)

因为正如医生所说:

getQName:返回属性的限定(加前缀)名称.

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

查看示例以获取属性名称和值


Her*_*rry 13

 @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);
}
Run Code Online (Sandbox Code Playgroud)