簡體   English   中英

使用SAX Parser,獲取屬性的值

[英]With SAX Parser, get an attribute's value

我正在使用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>

采用

attributes.getValue(i);

代替

attributes.getQName(i);

因為正如文檔所說:

getQName返回屬性的限定名稱(前綴)。

getValue通過限定(前綴)名稱查找屬性的值。

請參閱示例以獲取屬性名稱和值

 @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);
}

試試attributes.getValue(i)方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM