2

How to Wrap the data from a Yahoo Weather API.I have a code like this where city may return a null value and temperature may return 0. Please help me.

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

            }

    }

}
Arun Kumar
  • 6,534
  • 13
  • 40
  • 67

1 Answers1

0

In my library I've used JAXB in order to wrp yahoo weather responses. Here the code: https://github.com/fedy2/yahoo-weather-java-api

Fedy2
  • 3,147
  • 4
  • 26
  • 44