要开发一个门户。首页要有简单的天气预报。就是温度、和一句间端的天气描述(比如晴天啦,夜间有雨之类的)。
还望各位高手指点。搜了一天了,只能找到一些英文的。有什么办法才能找到中文的呢?
还望各位高手指点。搜了一天了,只能找到一些英文的。有什么办法才能找到中文的呢?
解决方案 »
- JSP 如何防 CC攻击
- 请教url跳转的问题…当top.location遇到apache/tomcat整合
- Connections could not be acquired from the underlying database
- struts2的标签s:tabbedPanel的返回页面出现多行空行急求解决!!
- 请问如何写计算机软件著作权登记所需要的材料?
- 运行.java文件,为什么把源码给显示出来了呀?
- 当用户点取了一个url后,连接到一个jsp处理页面,这个页面要根据上1页中url的文字内容来进行一些处理,如何获取url的问题内容呢?
- 求一个实现上传和下载文件的例子
- weblogic找不到类的错误有哪些地方可能出错?
- 兄弟们,救救小弟,关于jsp的select 框的问题,如解决不成就要通宵了!
- 如何用JS制作右键菜单
- hibernate如何获得统计函数的结果?
InputStream input = url.openStream();
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(false);
SAXParser parser = factory.newSAXParser();
parser.parse(input, new YahooHandler());自己定义一个YahooHandler来响应SAX事件:/**
* For more information, please visit: http://www.crackj2ee.com
* Author: Liao Xuefeng
*/
public class YahooHandler extends DefaultHandler { public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if("yweather:condition".equals(qName)) {
String s_date = attributes.getValue(3);
try {
Date publish = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm a z", Locale.US).parse(s_date);
//System.out.println("Publish: " + publish.toString());
}
catch (Exception e) {
e.printStackTrace();
throw new SAXException("Cannot parse date: " + s_date);
}
}
else if("yweather:forecast".equals(qName)) {
String s_date = attributes.getValue(1);
Date date = null;
try {
date = new SimpleDateFormat("dd MMM yyyy", Locale.US).parse(s_date);
}
catch (Exception e) {
e.printStackTrace();
throw new SAXException("Cannot parse date: " + s_date);
}
int low = Integer.parseInt(attributes.getValue(2));
int high = Integer.parseInt(attributes.getValue(3));
String text = attributes.getValue(4);
int code = Integer.parseInt(attributes.getValue(5));
System.out.println("Weather: "+ text + ", low=" + low + ", high=" + high);
}
super.startElement(uri, localName, qName, attributes);
}
}运行结果:Weather: Partly Cloudy, low=7, high=16
Weather: Sunny, low=7, high=20