网站:http://w1.weather.gov/xml/current_obs/index.xml;是美国气象站用Lat / Lon坐标标记的索引,它提供当前的当地天气观测。在文件中的2257个工作站中,每个10个线段看起来像这样:
<station>
<station_id>PADK</station_id>
<state>AK</state>
<station_name>Adak Island, Adak Airport</station_name>
<latitude>51.87778</latitude>
<longitude>-176.64583</longitude>
<html_url>http://weather.noaa.gov/weather/current/PADK.html</html_url>
<rss_url>http://weather.gov/xml/current_obs/PADK.rss</rss_url>
<xml_url>http://weather.gov/xml/current_obs/PADK.xml</xml_url>
</station>
目标是使用Android手机的GPS和地图路线信息搜索最近的纬度/经度匹配,然后下拉2行并使用该RSS链接解析并传递给TTS服务;因为手机是免提的“免提”。开车时体验。从Tasker开始,人们通常可以“获得”。加载全局var%HTTPD并从那里解析的站点,但该文件远远超出了可变大小限制。有没有人有合适的解决方法?
答案 0 :(得分:0)
您应该使用HttpURLConnection
之类的:
URL url = new URL("http://w1.weather.gov/xml/current_obs/index.xml");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
然后获取您的InputStream
并使用SAX Parser解析它,如:
// get a new SAXParser
SAXParser parser = factory.newSAXParser();
// parse the stream
parser.parse(is, handler);
handler
是您的课程HandlerBase
类。
SAX Parser是基于流的XML解析器。 SAX Parser有很多例子。只是谷歌他们。