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
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
117 | CORS 관련 레퍼런스 URL | 황제낙엽 | 2020.07.10 | 53 |
116 | Navigator 객체란? | 황제낙엽 | 2011.02.22 | 53 |
115 | Function.apply() 와 Function.call() | 황제낙엽 | 2011.10.07 | 51 |
114 | JavaScript 재입문 | 황제낙엽 | 2012.05.29 | 50 |
113 | insertAdjacentHTML Method | 황제낙엽 | 2005.12.19 | 50 |
112 | ECMA 스크립트의 JSON | 황제낙엽 | 2019.10.16 | 48 |
111 | String 에 trim() 함수 적용하기 | 황제낙엽 | 2011.08.28 | 48 |
110 | 3시간 걸려서 만든 입력폼 자릿수체크 스크립트 | 황제낙엽 | 2006.04.22 | 48 |
109 | 멤버 연산자 | 황제낙엽 | 2014.12.30 | 47 |
108 | 연산자 (===, ==, >=, <=) | 황제낙엽 | 2012.05.30 | 47 |
107 | [key:value] 형태로 object를 저장할 수 있는 Static영역의 해쉬맵 클래스 (Map) | 황제낙엽 | 2008.11.04 | 46 |
106 | Dynatrace For Ajax Performance | 황제낙엽 | 2010.08.18 | 45 |
105 | CORS(Cross-Origin Resource Sharing) - 3 | 황제낙엽 | 2017.03.07 | 45 |
» | 폼으로 XML 데이터 전송 (JSP+Javascript) | 황제낙엽 | 2005.12.04 | 43 |
103 | delete 연산자에 대한 고찰 | 황제낙엽 | 2012.06.11 | 42 |
102 | object clone | 황제낙엽 | 2011.07.08 | 41 |
101 | User Agent 관련 Reference URL | 황제낙엽 | 2011.02.22 | 41 |
100 | 잘못된 종속관계 해지에 따른 메모리 누수 예제 | 황제낙엽 | 2009.04.03 | 41 |
99 | [펌] 아사페릴의 사생활 - prototype과 __proto__ 와 constructor | 황제낙엽 | 2009.04.02 | 41 |
98 | withCredentials 관련 | 황제낙엽 | 2020.07.29 | 39 |