如何包装来自Yahoo Weather API的数据。我有这样的代码,其中城市可能返回一个null
值,而温度可能返回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);
}
}
}