package com.msi.manning.weather.data;

import java.io.InputStream;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

public class YWeatherSAXParser {
	
	public static WeatherRecord parseWeather(InputStream xml) throws Exception {
		WeatherRecord r = new WeatherRecord();
		
		SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        YWeatherHandler handler = new YWeatherHandler();
        xr.setContentHandler(handler);
        xr.parse(new InputSource(xml));
        // after parsed, get record
        r = handler.getWeatherRecord();
        r.setOverrideSevere(true); // override severe for dev/testing
		return r;
	}
	
}
