我想在Android应用程序中使用Google的非官方天气API。以Java获取XML文件的问题
我用这个代码:
//get the text from the edit text
userZip = zipCode.getText().toString();
//create a link using the zip code
//TODO sanitize input
System.out.println(userZip);
link = "http://www.google.com/ig/api?weather=" + userZip;
System.out.println(link);
//connect to the link
URL googleWeatherService = null;
try {
googleWeatherService = new URL(link);
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
SAXBuilder parser = new SAXBuilder();
try {
doc = parser.build(googleWeatherService);
} catch (JDOMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
但我得到的错误产生java.io.IOException无法打开http://www.google.com/ig/api?weather=08003(只使用08003作为一个例子)。
如果你去FF的链接,你会得到一个很好的天气XML文件,所以我做错了什么?
这看起来不错,但我使用JDOM,而不是dom4j所以没有SAXREADER ...什么是使用JDOM的等效过程? – 2011-02-14 18:22:42