如何从雅虎天气api包装数据?

问题描述:

如何从雅虎天气API。我总结的数据有这样一个 代码中的城市可能会返回一个null值和温度可能会返回。 请帮帮我。如何从雅虎天气api包装数据?

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

      } 

    } 

} 

在我的图书馆中,我使用JAXB以wrp雅虎天气响应。这里的代码:https://github.com/fedy2/yahoo-weather-java-api