我正在開發一個天氣應用程序。 Xml文件被成功解析。但我想讀這個值。如何解析Android中xml文件中標記值的屬性
<yweather:astronomy sunrise="6:03 am" sunset="6:17 pm"/>
但是,當我拿到天文,下至一個文本費爾德,則返回null。但在logcat中顯示天文標籤已通過。
我想要得到日出和日落的價值。請幫我解決一下這個。在此先感謝
XmlHelper.java
@Override
public void endElement(String uri, String localName, String qName) throws SAXException
{
currTag = false;
if(localName.equalsIgnoreCase("pubDate")) post.setDescription(currTagVal);
else if(localName.equalsIgnoreCase("lastBuildDate")) post.setLastBuildDate(currTagVal);
else if(localName.equalsIgnoreCase("yweather:location city")) post.setLocation(currTagVal);
else if(localName.equalsIgnoreCase("channel")) Yweather.add(post);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
Log.i(TAG, "TAG: " + localName);
currTag = true; currTagVal = ""; // Whenever <post> element is encountered it will create new object of PostValue
if(localName.equals("channel"))
{
post = new WeatherValues();
}
}
MainActivity.java
@Override
protected void onPostExecute(Void result)
{
StringBuilder builder = new StringBuilder();
for(WeatherValues post : helper.Yweather) {
builder.append(post.getLocation());
}
tvResponse.setText(builder.toString());
pd.dismiss();
}
}
這是xml文件 http://weather.yahooapis.com/forecastrss?w=2189713
感謝您的評論。 – Isuru 2014-09-04 03:54:37
歡迎您。希望它有幫助;) – 2014-09-05 19:32:49