【发布时间】:2013-07-25 04:15:47
【问题描述】:
如何包装来自 Yahoo Weather API 的数据。我有这样的代码
其中 city 可能返回 null 值,并且 temperature 可能返回 0。
请帮帮我。
public class Handalinxml extends DefaultHandler{
Xmldatacollected info=new Xmldatacollected();
public String getInformation()
{
return info.dataToString();
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if(localName.equals("yweather:location"))
{
String city=attributes.getValue("city");
info.setCity(city);
}
if(localName.equals("yweather:forecast"))
{
String t=attributes.getValue("high");
int temp=Integer.parseInt(t);
info.setTemp(temp);
}
}
}
【问题讨论】: