Develop
2013.04.23 16:18
[jsp] RSS(xml) 파싱해서 보여주기 ㅎㅎ
조회 수 13217 댓글 0
첨부 '1' |
---|
지인 부탁으로 만들었던 초간단 샘플~
버리기 아까워서 소스코드랑 샘플 xml 올려놓음..
한국일보 RSS 긁어오는 JSP 소스코드 샘플..
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ page import="java.net.URL" %> <%@ page import="java.util.List" %> <%@ page import="org.xml.sax.InputSource" %> <%@ page import="org.jdom.Document" %> <%@ page import="org.jdom.Element" %> <%@ page import="org.jdom.input.SAXBuilder" %> <% List list = null; try{ SAXBuilder parser = new SAXBuilder(); parser.setValidation(false); parser.setIgnoringElementContentWhitespace(true); //URL url = new URL("http://jsp.hooni.net/rss/sample.xml"); URL url = new URL("http://rss.hankooki.com/news/hk00_list.xml"); InputSource is = new InputSource(url.openStream()); Document doc = parser.build(is); Element root = doc.getRootElement(); Element channel = root.getChild("channel"); list = channel.getChildren("item"); }catch(Exception e){ e.getStackTrace(); } %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>RSS 열라 파씽</title> </head> <body> <ul> <% if(list!=null){ for(int i=0; i<list.size(); i++){ Element el = (Element) list.get(i); %> <li><a href='<%=el.getChildText("link")%>' target=_news> <%=el.getChildText("title")%></a></li> <% } }else{ %> <li>잠시 후 다시 접속하여 주십시오.</li> <% } %> </ul> </body> </html>
-
iOS 에서 쓸만한 오프라인 구글지도 찾기
-
[doc] 웜 프레임워크 검증환경 구축(작성중..)
-
여기저기서 모은 VoIP(인터넷전화) 자료들~
-
티스토리 테이블 html,css 구문
-
[owasp] 10대 웹어플리케이션 보안 취약
-
[ppt] 웜 과제 진행사항(프레임워크 검증환경 구축) 보고
-
라우팅 경로 결정 영향 요소 ㅋㅋ
-
OGNL(Object Graph Navigation Language)
-
영어의 12 시제 (The twelve tenses of English)
-
[ios] APNS 클라이언트 구현 (pdf)
-
[c] 윈도우 API sin 함수 출력..
-
[router] 설정과 기본 명령어들 모음