【发布时间】:2014-09-03 11:25:37
【问题描述】:
我正在开发一个天气应用程序。 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();
}
}
【问题讨论】:
标签: android xml-parsing saxparser xml-attribute