xml 기상청 날씨 파싱

   
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.List" %>
<%@page import="java.net.URL" %>
<%@page import="org.jdom.Document" %>
<%@page import="org.jdom.Element" %>
<%@page import="org.jdom.input.SAXBuilder" %>
<%@page import="org.xml.sax.*" %>
<%@page import="java.text.*" %>







<%
 List list = null;
 try
 {
  SAXBuilder parser = new SAXBuilder();
  parser.setValidation(false);
  parser.setIgnoringElementContentWhitespace(true);
  URL url = new URL("http://www.kma.go.kr/wid/queryDFS.jsp?gridx=59&gridy=125");
  InputSource is = new InputSource(url.openStream());
  Document doc = parser.build(is);
  Element root = doc.getRootElement();

  Element channel = root.getChild("body");
  list = channel.getChildren("data");
%>
<%
   Element el = (Element)list.get(0);
 %>
 
   
  • ---------------------------------
  • 시간:<%=el.getChildText("hour")%>시
  • 현재온도:<%=el.getChildText("temp")%>℃
  • 최고온도:<%=el.getChildText("tmx")%>℃
  • 최저온도:<%=el.getChildText("tmn")%>℃
  • 날씨:<%=el.getChildText("wfKor")%>
  • 강수확률:<%=el.getChildText("pop")%>%
  • 습도:<%=el.getChildText("reh")%>%
  • ---------------------------------


  • <% }catch(Exception e){ e.getStackTrace(); }