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
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
17 | Barcode Detection API | 황제낙엽 | 2023.08.06 | 7 |
16 | (Copilot) 바닐라 스크립트가 뭐지? | 황제낙엽 | 2023.02.24 | 7 |
15 | 배열에 대한 루프문 조회 (loop iterator) | 황제낙엽 | 2023.03.01 | 3 |
14 | (Copilot) JSON 객체의 내부 데이터 리스트 길이를 구하는 방법 | 황제낙엽 | 2023.03.30 | 2 |
13 | fetch() 함수 사용 예제 | 황제낙엽 | 2023.11.23 | 1 |
12 | 현재 document 의 host 와 port 를 얻는 방법 | 황제낙엽 | 2023.10.03 | 1 |
11 | 모바일 브라우저에서 file input element 를 이용하여 여러장의 이미지를 서버에 전송하려 할때 | 황제낙엽 | 2023.08.21 | 1 |
10 | navigator.mediaDevices | 황제낙엽 | 2023.08.21 | 1 |
9 | 체크박스에 체크된 항목 개수 구하기 | 황제낙엽 | 2023.06.10 | 1 |
8 | JSON 클래스가 지원하는 function | 황제낙엽 | 2023.03.31 | 1 |
7 | CryptoJS 를 이용한 암호화 | 황제낙엽 | 2023.02.15 | 1 |
6 | json 데이터 내의 변수명에 prefix 로 type 표현하기 | 황제낙엽 | 2024.04.15 | 0 |
5 | (Bard) FileReader 로 여러개의 파일을 read 하는 법 | 황제낙엽 | 2023.08.23 | 0 |
4 | How to build a file upload service with vanilla JavaScript | 황제낙엽 | 2023.08.22 | 0 |
3 | (Bard) JavaScript로 JSON 배열을 작성하는 방법 | 황제낙엽 | 2023.08.21 | 0 |
2 | [URLSearchParams] URL 파라미터(매개변수) 값 가져오기 | 황제낙엽 | 2023.02.02 | 0 |
1 | 정규식을 이용한 이메일 검증 스크립트 | 황제낙엽 | 2023.06.25 | 0 |