sitelink1 | |
---|---|
sitelink2 | |
sitelink3 | |
sitelink4 | |
extra_vars4 | |
extra_vars5 | |
extra_vars6 |
Client Side: JavaScript 에서 XML 노드에 관련된 처리(노드 삽입/삭제/추가)를 수행한다. POST메소드를 이용해서 XML의 모든 내용을 서버에 전송한다.
Server Side: 전송된 XML문서를 저장하거나 그 외에 (Soap 통신등)작업을 수행한다.
관련기술. MSXML : (MSDN Library) - XML Web Services - XML Core - MSXML - XML - XML Reference
기타 XML 기술. 처리 순서
1. HTML, JSP 페이지에서 XML노드 작업을 한다.
2. 히든 필드로 XML을 넣는다.
3. 폼을 전송한다.
4. XML 파일을 파싱한다.
참조 파일 xml.html(클라이언트 측 파일) xml.jsp (서버측 파일)
[xml.html]
<html>
<head>
<script language="javascript">
// 지금은 노드 작업 없이 xml 내용만 전달한다.
// 실제 xml 노드 작업은 관련 메소드를 이용해서 수행 할 수 있다.
function readIt() {
var doc = document.all.SAMPLE_XML.documentElement;
alert(doc.text);
alert(doc.xml);
// <?xml version="1.0" encoding="euc-kr"?> 는 doc.xml 속성에 포함되지 않는다.
document.xml_form.xml_content.value=doc.xml;
return true;
}
</script>
</head>
<body>
<XML ID="SAMPLE_XML">
<?xml version="1.0" encoding="euc-kr"?>
<BOOK category="fiction">
<TITLE> Jonathan </TITLE>
<AUTHOR> 김영규 </AUTHOR> </BOOK> </XML>
<input type="button" value="read xml" omclick="javascript:readIt()"/>
<form name="xml_form" action="xml.jsp" method="post" omSubmit="return readIt();">
<input type="hidden" name="xml_content"/>
<input type="hidden" name="encoding" value="euc-kr"/>
<input type="submit"/>
</form>
</body>
</html>
[xml.jsp]
<%@ page contentType="text/html; charset=euc-kr" %>
<%@ page import="java.io.*"%>
<%@ page import="org.w3c.dom.*"%>
<%@ page import="javax.xml.parsers.*"%>
<%
String xmlContent = request.getParameter("xml_content");
String encoding = request.getParameter("encoding");
System.out.println("xml content");
xmlContent = new String(xmlContent.getBytes("8859_1"), "KSC5601");
StringBuffer content = new StringBuffer();
// <?xml version="1.0" encoding="euc-kr"?> 은 전달되지 않는다.
// 한글을 사용하지 않았을 경우에는 이런 작업은 생략할 수 있다.
content.append("<?xml version="1.0" encoding="").append(encoding).append(""?>");
content.append(xmlContent);
xmlContent = content.toString();
System.out.println(xmlContent);
String author = "";
String title = "";
ByteArrayInputStream in = new ByteArrayInputStream(xmlContent.getBytes("KSC5601"));
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(in);
Element rootEl = doc.getDocumentElement();
NodeList list = rootEl.getElementsByTagName("AUTHOR");
if(list.getLength() > 0) {
Element authorEl = (Element) list.item(0);
author = authorEl.getFirstChild().getNodeValue();
System.out.println(author);
}
list = rootEl.getElementsByTagName("TITLE");
if(list.getLength() > 0) {
Element titleEl = (Element) list.item(0);
title = titleEl.getFirstChild().getNodeValue();
System.out.println(title);
}
} catch (Exception ex) {
ex.printStackTrace();
}
%>
<html>
<body>
<table>
<tr>
<td> Title </td>
<td><%= title %> </td>
</tr>
<tr>
<td> Author </td>
<td><%= author %> </td>
</tr>
</table>
</body>
</html>
Server Side: 전송된 XML문서를 저장하거나 그 외에 (Soap 통신등)작업을 수행한다.
관련기술. MSXML : (MSDN Library) - XML Web Services - XML Core - MSXML - XML - XML Reference
기타 XML 기술. 처리 순서
1. HTML, JSP 페이지에서 XML노드 작업을 한다.
2. 히든 필드로 XML을 넣는다.
3. 폼을 전송한다.
4. XML 파일을 파싱한다.
참조 파일 xml.html(클라이언트 측 파일) xml.jsp (서버측 파일)
<html>
<head>
<script language="javascript">
// 지금은 노드 작업 없이 xml 내용만 전달한다.
// 실제 xml 노드 작업은 관련 메소드를 이용해서 수행 할 수 있다.
function readIt() {
var doc = document.all.SAMPLE_XML.documentElement;
alert(doc.text);
alert(doc.xml);
// <?xml version="1.0" encoding="euc-kr"?> 는 doc.xml 속성에 포함되지 않는다.
document.xml_form.xml_content.value=doc.xml;
return true;
}
</script>
</head>
<body>
<XML ID="SAMPLE_XML">
<?xml version="1.0" encoding="euc-kr"?>
<BOOK category="fiction">
<TITLE> Jonathan </TITLE>
<AUTHOR> 김영규 </AUTHOR> </BOOK> </XML>
<input type="button" value="read xml" omclick="javascript:readIt()"/>
<form name="xml_form" action="xml.jsp" method="post" omSubmit="return readIt();">
<input type="hidden" name="xml_content"/>
<input type="hidden" name="encoding" value="euc-kr"/>
<input type="submit"/>
</form>
</body>
</html>
<%@ page contentType="text/html; charset=euc-kr" %>
<%@ page import="java.io.*"%>
<%@ page import="org.w3c.dom.*"%>
<%@ page import="javax.xml.parsers.*"%>
<%
String xmlContent = request.getParameter("xml_content");
String encoding = request.getParameter("encoding");
System.out.println("xml content");
xmlContent = new String(xmlContent.getBytes("8859_1"), "KSC5601");
StringBuffer content = new StringBuffer();
// <?xml version="1.0" encoding="euc-kr"?> 은 전달되지 않는다.
// 한글을 사용하지 않았을 경우에는 이런 작업은 생략할 수 있다.
content.append("<?xml version="1.0" encoding="").append(encoding).append(""?>");
content.append(xmlContent);
xmlContent = content.toString();
System.out.println(xmlContent);
String author = "";
String title = "";
ByteArrayInputStream in = new ByteArrayInputStream(xmlContent.getBytes("KSC5601"));
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(in);
Element rootEl = doc.getDocumentElement();
NodeList list = rootEl.getElementsByTagName("AUTHOR");
if(list.getLength() > 0) {
Element authorEl = (Element) list.item(0);
author = authorEl.getFirstChild().getNodeValue();
System.out.println(author);
}
list = rootEl.getElementsByTagName("TITLE");
if(list.getLength() > 0) {
Element titleEl = (Element) list.item(0);
title = titleEl.getFirstChild().getNodeValue();
System.out.println(title);
}
} catch (Exception ex) {
ex.printStackTrace();
}
%>
<html>
<body>
<table>
<tr>
<td> Title </td>
<td><%= title %> </td>
</tr>
<tr>
<td> Author </td>
<td><%= author %> </td>
</tr>
</table>
</body>
</html>
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
26 | Page Refresh/Reload | 황제낙엽 | 2007.08.24 | 517 |
25 | Javascript 내장객체 String | 황제낙엽 | 2007.04.10 | 630 |
24 |
유용한 자바스크립트 예제 몇가지 (Tree 및...)
![]() | 황제낙엽 | 2005.10.20 | 423 |
23 | 자바 스크립트 플러그인 | 황제낙엽 | 2005.11.22 | 401 |
22 |
JAVASCRIPT REFERENCE 파일
![]() | 황제낙엽 | 2005.11.22 | 435 |
21 |
JAVASCRIPT Debuger 프로그램
![]() | 황제낙엽 | 2005.11.22 | 320 |
20 |
SelectBox 밑에 CheckBox가 포함된 리스트 만들기
![]() | 황제낙엽 | 2007.01.16 | 841 |
19 | 3시간 걸려서 만든 입력폼 자릿수체크 스크립트 | 황제낙엽 | 2006.04.22 | 415 |
18 | innerHTML | 황제낙엽 | 2005.12.19 | 465 |
17 | insertAdjacentHTML Method | 황제낙엽 | 2005.12.19 | 570 |
» | 폼으로 XML 데이터 전송 (JSP+Javascript) | 황제낙엽 | 2005.12.04 | 442 |
15 | Methods and properties of Microsoft.XMLDOM | 황제낙엽 | 2005.12.04 | 406 |
14 | 슬라이딩 메뉴 | 황제낙엽 | 2005.12.02 | 464 |
13 | XML+JS 연동 다중셀렉트박스 (1) - <font color="brown">(MS Explorer 전용)</brown> | 황제낙엽 | 2005.12.02 | 369 |
12 | 풍선 도움말 | 황제낙엽 | 2005.11.24 | 310 |
11 | 소스 보기 막기 | 황제낙엽 | 2005.11.18 | 513 |
10 | 카페의 회람 . 막기 소스 | 황제낙엽 | 2005.10.21 | 218 |
9 | 브라우저에서 뒤로 가기 막기와 펑션키(function key) 막기 | 황제낙엽 | 2005.10.21 | 554 |
8 | 아이디 생성 조건 검사 자바스크립트 모듈 | 황제낙엽 | 2004.11.18 | 459 |
7 | 마우스 오버시 살짝 뒤로 물러나는 듯한 링크 -_-;; | 황제낙엽 | 2003.01.04 | 443 |