Xml은 데이터를 저장하기 위한 문서이다. 이 때문에 Internet explorer에서는 다른 프로그램을 사용하지 않고서도 데이터를 추출해낼 수 있는 여러 가지 방법을 제공한다. 이 방법들 중 하나가 '데이터 바인딩'이다.
데이터 원본 객체(DSO: Data Source Object) 사용하기
DSO는 문서를 읽어서 페이지의 나머지 부분에서 그 데이터를 사용할 수 있도록 하기 위해 사용한다
|
<head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Name</title> </head>
<body> Name:<span id="name">charles</span><br /> ID:<span id="customerID">58704</span><br /> Purchase date: Date: <span id="purchasedate">10/15/2003</span><br /> Department:<span id="deparment">meat</span><br /> Product:<span id="productname">ham</span><br /> // 필드
Name:<span id="name">franklon</span><br /> ID:<span id="customerID">58705</span><br /> Purchase date: Date: <span id="purchasedate">10/15/2003</span><br /> Department:<span id="deparment">produce</span><br /> Product:<span id="productname">tomatoes</span><br />
Name:<span id="name">phoebe</span><br /> ID:<span id="customerID">58706</span><br /> Purchase date: Date: <span id="purchasedate">10/15/2003</span><br /> Department:<span id="deparment">meat</span><br /> Product:<span id="productname">turkey</span><br />
Name:<span id="name">mark</span><br /> ID:<span id="customerID">58707</span><br /> Purchase date: Date: <span id="purchasedate">10/15/2003</span><br /> Department:<span id="deparment">meat</span><br /> Product:<span id="productname">beef</span><br />
Name:<span id="name">nancy</span><br /> ID:<span id="customerID">58708</span><br /> Purchase date: Date: <span id="purchasedate">10/15/2003</span><br /> Department:<span id="deparment">frozen</span><br /> Product:<span id="productname">brococoli</span><br /> //레코드
</body> |
-
고객에 대한 판매 데이터를 저장하고 있다
Html 문서 형식의 데이터를 처리하는 가장 일반적인 방법(MSHTML DSO)
DSO에서는 이러한 문서를 읽어 들여 레코드셋으로 변환 시킨다
데이터를 html 구성요소와 바인딩 하기
이들 속성과 연결하려면, 구성요소의 datasrc(dso의 이름을 지정)와 datafld(구성요소를 연결하고자 하는 데이터 필드의 이름을 지정)를 설정해야 한다
|
<head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>data binding with the mshtml dso</title> </head>
<body> <center> <h1>data binding with the mshtml dso</h1>
<object id="dsoCustomer" data="chapter8ex1.html" height="0" width="0"></object> //dsoCustomer라는 MSHTML 컨트롤을 웹 페이지에 추가하고 DSO를 chapter8ex1.html에 연결 name:<input type="text" datasrc="#dsoCustomer" datafld="name" size="10" /> <br /><br /><br /> id: <input type="text" datasrc="#dsoCustomer" datafld="customerID" size="5" /> <br /><br /> purchase date: <span datasrc="#dsoCustomer" datafld="purchasedate"></span> <br /> <br /> department:<select datasrc="#dsoCustomer" datafld="department" size="1" > <option value="produce">produce</option> <option value="meat">meat</option> <option value="frozen">frozen</option> </select>
<br /> <br /> product:<span datasrc="#dsoCustomer" datafld="productname"></span>
<br /><br /> <button onclick="dsoCustomer.recordest.moveFirst()"> < <</button> //첫 레코드로 이동 <button onclick="if(!dsoCustomer.recordest.BOF)dsoCustomer.recordest.movePrevious()" ><</button> // 이전 레코드로 이동 <button onclick="if(!dsoCustomer.recordest.EOF)dsoCustomer.recordest.moveNext()">> </button> // 다음 레코드로 이동 <button onclick="dsoCustomer.recordset.moveLast()">> > </button> //마지막 레코드로 이동</center> </body> |
BOF(Beginning of File) - 레코드셋의 시작 위치, EOF(End of File)- 레코드셋의 끝 위치
XML과 데이터 바인딩 사용하기
|
<?xml version="1.0" encoding="UTF-8"?> <customers> <customer> //요소 <name>charles</name> <customer_id>58704</customer_id> <purchase_date>10/15/2003</purchase_date> <department>meat</department> <product_name>ham</product_name> </customer>
<customer> <name>franklin</name> <customer_id>58705</customer_id> <purchase_date>10/15/2003</purchase_date> <department>produce</department> <product_name>tomatoes</product_name> </customer>
<customer> <name>phoebe</name> <customer_id>58706</customer_id> <purchase_date>10/15/2003</purchase_date> <department>meat</department> <product_name>turkey</product_name> </customer>
<customer> <name>mark</name> <customer_id>58707</customer_id> <purchase_date>10/15/2003</purchase_date> <department>meat</department> <product_name>beef</product_name> </customer>
<customer> <name>nancy</name> <customer_id>58708</customer_id> <purchase_date>10/15/2003</purchase_date> <department>frozen</department> <product_name>broccoli</product_name> </customer> </customers> |
XML DSO의 속성, 메소드, 이벤트
XML DSO의 레코드셋 객체의 속성
-
absolutePage: 현재 레코드가 있는 페이지
-
absolutePosition: 현재 레코드의 레코드셋에서의 위치
-
BOF: 현재 레코드 포인터가 첫 번째 레코드보다 앞에 있다면 참이다.
-
cacheSize: 지역적으로 캐시에 보관되는 레코드셋 객체의 레코드 수
-
cursorLocation: 레코드셋의 커서 위치
-
cursorType: 사용되고 있는 데이터베이스 커서의 종류
-
editMode: 편집이 진행중인지를 알려주는 속성
-
EOF: 현재 레코드 포인터가 마지막 레코드보다 뒤에 있다면 참이다
-
lockType: 강제로 데이터베이스를 잠그는 기능의 종류
-
maxRecords: 질의에 의해 레코드셋으로 되돌려주는 레코드의 최대수
-
pageCount: 레코드셋이 포함하는 데이터의 페이지 수
-
pageSize: 한페이지를 구성하는 레코드의 수
-
recordCount: 레코드셋에서 레코드의 수
-
state: 레코드셋의 상태(열려 있는지 또는 닫혀 있는지의 여부)
-
status: 현재 레코드의 상태
-
stayInsync: 계층형 레코드셋의 데이터 원본과 계속 연결을 유지할 것인지에 대한 속성
XML DSO 내의 레코드셋에 대한 메소드
-
addNew: 레코드셋에 새 레코드를 추가한다
-
cancel: 현재 진행중인 Execute 또는 Open 요청 작업의 실행을 취소한다
-
cancelUpdate: 현재 진행중인 Update 작업을 취소한다
-
clone: 레코드셋의 복사본을 만든다
-
close: 레코드셋을 닫는다
-
delete: 현재 레코드를 삭제한다
-
find: 레코드셋을 검색한다
-
getRows: 레코드를 읽어서 배열에 저장한다
-
getString: 레코드셋을 문자열로 가져온다
-
move: 현재 레코드의 위치를 이동한다
-
moveFirst, moveLast, moveNext, moveprevious: 레코드셋에서 여러 위치로 이동할 수 있다
-
nextRecordset: 현재 레코드셋 객체를 지우고, 다음 레코드셋을 되돌려준다., 계층형 레코드셋에서 사용한다
-
open: 데이터 베이스를 연다
-
requery: 레코드셋을 생성했던 질의를 다시 실행한다
-
save: 레코드셋을 파일에 저장한다
XML DSO는 처리할 수 있는 여러 개의 이벤트
-
onCellChange: 바운드 컨트롤 내의 데이터가 변경되어 셀이 초점을 잃게 될 때 발생한다
-
onDataAvailable: 데이터 그룹을 다운로드할 때 마다 발생한다
-
onDatasetChanged: 데이터 집합을 바뀔 때 발생한다
-
onDatasetComplete: 데이터를 다운로드 받아서 사용할 준비가 되었을 때 발생한다
-
onReadyStateChange: ReadyState 속성이 변경될 때 발생한다
-
onRowEnter: 새 레코드가 현재 레코드가 될 때 발생한다
-
onRowExit: 현재 레코드를 떠나기 전에 발생한다
-
onRowsDelete: 한 줄이 삭제될 때 발생한다
-
onRowsInserted: 한 줄이 삽입될 때 발생한다
|
<head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>single record bindint usint xml</title> </head>
<xml src="../Altova/XMLSpy2008/ch08ex3.xml" id="customers"></xml>
<body> <center> <h1>single record bindint usint xml data islands</h1> name:<input type="text" datasrc="#customers" datafld="name" size="10" /> <br /> <br /> customer id: <input type="text" datasrc="#customers" datafld="customer_id" size="5" /> <br /> <br /> purchase date: <span datasrc="#customers" datafld="purchase_date" ></span><br /> product:<span datasrc="#customers" datafld="product_name" ></span> <br />
department:<select datasrc="#customers" datafld="department" size="1"> <option value="meat">meat</option> <option value="produce">produce</option> <option value="frozen">frozen</option> </select> <br /> <button onclick="customers.recordset.moveFirst()"> <<</button> <button onclick="if(!customers.recordset.BOF) customers.recordset.movePrevious()"><</button> <button onclick="if(!customers.recordset.EOF) customers.recordset.moveNext()">></button> <button onclick="customers.recordset.moveLast()"> > > </button> </center> </body> |
|
<head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>accessing individual data fields</title> <xml id="customer" src="../Altova/XMLSpy2008/ch08ex3.xml"></xml> <script language="javascript"> function viewData() { while(!customer.recordset.EOF){ div1.innerHTML += customer.recordset("name")+ "bought" + customer.recordset("product_name") + "from the" + customer.recordset("department" ) + "department.<br>" customer.recordset.moveNext() } }
</script>
</head>
<body> <center> <h1>accessing individual data fields</h1> </center> <form> <center> <input type="button" value="View data" onclick="viewData()" /> </center> </form> <div id="div1"></div> </body> |
테이블 형식의 데이터 바인딩과 XML
|
<head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>tabular binding with xml data is</title> </head>
<body> <center > <h1>tabular binding with xml data islands</h1> </center> <xml src="../Altova/XMLSpy2008/ch08ex3.xml" id="customers"></xml>
<table datasrc="#customers" cellspacing="10"> <thead> <tr> <th>name</th> <th>customer id</th> <th>purchase date</th> <th>department</th> <th>product</th> </tr> </thead>
<tbody> <tr> <td> <span datafld="name"></span> </td> <td> <span datafld="customer_id"></span> </td> <td> <span datafld="purchase_date"></span> </td> <td> <span datafld="department"></span> </td> <td> <span datafld="product_name"></span> </td> </tr> </tbody> </table> </body> |
XML DSO 단일 레코드 데이터 연결하기
이 DSO는 Internet Explorer 내부에 존재하지 않고 Java 애플릿으로 구현
|
<head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>single record bindint using the</title> </head>
<body> <center> <h1>single record bindint using the xml dso</h1>
<applet code="com.ms.xml.dso.XMLDSO.class" id="dsocustomer" width="0" height="0" mayscript="true"> <param name="url" value="C:\Users\Administrator\Documents\Altova\XMLSpy2010\ch08ex3.xml" /> //xml 문서의 url을 xml dso 애플릿에 인수로 전달하고 있다 </applet>
name:<input type="text" datasrc="#dsocustomer" datafld="name" size="10" /><br /> customer id: <input type="text" datasrc="#dsocustomer" datafld="customer_id" size="5" /><br /> purchase date: <span datasrc="#dsocustomer" datafld="purchase_date" ></span><br /> department: <select datasrc="#dsocustomer" datafld="department" size="1"> <option value="meat">meat</option> <option value="produce">produce</option> <option value="frozen">frozen</option> </select> <br /> product:<span datasrc="#dsocustomer" datafld="product_name"></span> <br /> <button onclick="dsocustomer.recordset.moveFirst()">< < </button> <button onclick="if(!dsocustomer.recordset.BOF)dsocustomer.recordset.movePrevious()"><</button> <button onclick="if(!dsocustomer.recordset.EOF)dsocustomer.recordset.moveNext()" >> </button> <button onclick="dsocustomer.recordset.moveLast()">> > </button> </center> </body> |
XML DSO와 테이블 형태의 데이터 바인딩
|
<head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>binding the xml dso to tables</title> </head>
<body> <center> <h1>binding the xml dso to tables</h1>
<applet code="com.ms.xml.dso.XMLDSO.class" id="customers" width="0" height="0"> <param name="url" value="C:\Users\Administrator\Documents\Altova\XMLSpy2010\ch08ex3.xml" /> </applet>
<table datasrc="#customers" cellspacing="10"> <thead> <tr> <th>name</th> <th>customer id</th> <th>purchase date</th> <th>department</th> <th>product</th> </tr> </thead>
<tbody> <tr> <td> <span datafld="name"></span> </td> <td> <span datafld="customer_id"></span> </td> <td> <span datafld="purchase_date"></span> </td> <td> <span datafld="department"></span> </td> <td> <span datafld="product_name"></span> </td>
</tr> </tbody>
</table> </center> </body> |
XML과 계층형 데이터
|
<?xml version="1.0" encoding="UTF-8"?> <customers> <customer> <name>charles</name> <record> <customer_id>58704</customer_id> <purchase_date>10/15/2003</purchase_date> <department>meat</department> <product_name>ham</product_name> <delivery> //배달 레코드 <date>10/20/2003</date> <total_cost>$1.99</total_cost> </delivery> <delivery> <date>10/25/2003</date> <total_cost>$1.49</total_cost> </delivery> </record> </customer>
<customer> <name>franklin</name> <record> <customer_id>58705</customer_id> <purchase_date>10/15/2003</purchase_date> <department>produce</department> <product_name>tomatoes</product_name> <delivery> <date>10/20/2003</date> <total_cost>$3.00</total_cost> </delivery> <delivery> <date>10/25/2003</date> <total_cost>$2.95</total_cost> </delivery> </record> </customer>
<customer> <name>phoebe</name> <record> <customer_id>58706</customer_id> <purchase_date>10/15/2003</purchase_date> <department>meat</department> <product_name>turkey</product_name> <delivery> <date>10/20/2003</date> <total_cost>$4.99</total_cost> </delivery> <delivery> <date>10/25/2003</date> <total_cost>$8.99</total_cost> </delivery> </record> </customer> <customer> <name>mark</name> <record> <customer_id>58707</customer_id> <purchase_date>10/15/2003</purchase_date> <department>meat</department> <product_name>beef</product_name> <delivery> <date>10/20/2003</date> <total_cost>$3.95</total_cost> </delivery> <delivery> <date>10/25/2003</date> <total_cost>$6.95</total_cost> </delivery> </record> </customer> <customer> <name>nanvy</name> <record> <customer_id>58708</customer_id> <purchase_date>10/15/2003</purchase_date> <department>frozen</department> <product_name>broccoli</product_name> <delivery> <date>10/20/2003</date> <total_cost>$1.99</total_cost> </delivery> <delivery> <date>10/25/2003</date> <total_cost>$2.99</total_cost> </delivery> </record> </customer>
</customers> |
|
<head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>using xml with hierarchical reco</title> </head>
<body> <center> <h1>using xml with hierarchical records</h1> <xml src="C:\Users\Administrator\Documents\Altova\XMLSpy2010\ch08ex9.xml" id="dsocustomer"></xml> <table datasrc="#dsocustomer" border="1"> <tr> <th><div datafld="name"></div></th> <td> <table datasrc="#dsocustomer" datafld="record"> <tr> <td> <table datasrc="#dsocustomer" cellpadding="5" datafld="record.delivery"> <tr align="left"> <th>date</th> <th>total cost</th> </tr> <tr align="left"> <td><div datafld="date"></div></td> <td><div datafld="total_cost"></div></td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </center> </body> |
XML 문서에서 가변 크기의 계층형 데이터 처리하기
|
<?xml version="1.0" encoding="UTF-8"?> <customers> <customer> <name>charles</name> <record> <customer_id>58704</customer_id> <purchase_date>10/15/2003</purchase_date> <department>meat</department> <product_name>ham</product_name> <delivery> <date>10/20/2003</date> <total_cost>$1.99</total_cost> </delivery> <delivery> <date>10/25/2003</date> <total_cost>$1.49</total_cost> </delivery> <delivery> <date>10/25/2003</date> <total_cost>$1.49</total_cost> </delivery> </record> </customer>
<customer> <name>franklin</name> <record> <customer_id>58705</customer_id> <purchase_date>10/15/2003</purchase_date> <department>produce</department> <product_name>tomatoes</product_name> <delivery> <date>10/20/2003</date> <total_cost>$3.00</total_cost> </delivery> </record> </customer>
<customer> <name>phoebe</name> <record> <customer_id>58706</customer_id> <purchase_date>10/15/2003</purchase_date> <department>meat</department> <product_name>turkey</product_name> <delivery> <date>10/20/2003</date> <total_cost>$4.99</total_cost> </delivery> <delivery> <date>10/25/2003</date> <total_cost>$8.99</total_cost> </delivery> </record> </customer>
<customer> <name>mark</name> <record> <customer_id>58707</customer_id> <purchase_date>10/15/2003</purchase_date> <department>meat</department> <product_name>beef</product_name> <delivery> <date>10/20/2003</date> <total_cost>$3.95</total_cost> </delivery> <delivery> <date>10/25/2003</date> <total_cost>$6.95</total_cost> </delivery> </record> </customer>
<customer> <name>nancy</name> <record> <customer_id>58708</customer_id> <purchase_date>10/15/2003</purchase_date> <department>frozen</department> <product_name>broccoli</product_name> <delivery> <date>10/20/2003</date> <total_cost>$1.99</total_cost> </delivery> <delivery> <date>10/25/2003</date> <total_cost>$2.99</total_cost> </delivery> <delivery> <date>5-3-2002</date> <total_cost>$7200.00</total_cost> </delivery> </record> </customer> </customers> |
|
<head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>variable size hierarchical recor</title> </head>
<body> <center> <h1>variable size hierarchical records</h1>
<xml src="../Altova/XMLSpy2010/ch08ex11.xml" id="customers"></xml> <table datasrc="#customers" border="1"> <tr> <th><div datafld="name"></div></th> <td> <table datasrc="#customers" datafld="record"> <tr> <td> <table datasrc="#customers" cellpadding="3" datafld="record.delivery"> <tr align="left"> <th>date</th> <th>amount</th> </tr> <tr align="left"> <td><div datafld="date"></div></td> <td><div datafld="total_cost"></div></td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </center> </body> |
XML 데이터 검색하기
|
<?xml version="1.0" encoding="UTF-8"?> <customers> <customer> <name>charles</name> <customer_id>58704</customer_id> <purchase_date>10/15/2003</purchase_date> <department>meat</department> <product_name>ham</product_name> </customer> <customer> <name>frnklin</name> <customer_id>58705</customer_id> <purchase_date>10/15/2003</purchase_date> <department>produce</department> <product_name>tomatoes</product_name> </customer>
<customer> <name>phoebe</name> <customer_id>58706</customer_id> <purchase_date>10/15/2003</purchase_date> <department>meat</department> <product_name>turkey</product_name> </customer>
<customer> <name>mark</name> <customer_id>58707</customer_id> <purchase_date>10/15/2003</purchase_date> <department>meat</department> <product_name>beef</product_name> </customer>
<customer> <name>nancy</name> <customer_id>58708</customer_id> <purchase_date>10/15/2003</purchase_date> <department>frozen</department> <product_name>broccoli</product_name> </customer> <customer> <name>nancy</name> <customer_id>58709</customer_id> <purchase_date>10/15/2003</purchase_date> <department>produce</department> <product_name>tomatoes</product_name> </customer> </customers> |
|
<head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>searching xml-based databases</title> <xml id="customers" src="../Altova/XMLSpy2010/ch08ex13.xml"></xml> <script language="javascript"> function findmatches() { var searchFor= form1.text1.value.toLowerCase()
while(!customers.recordset.EOF){ var currentName = new String(customers.recordset("name")) currentName = currentName.toLowerCase() if(currentName.indexOf(searchFor)>=0){ divMessage.innerHTML += customers.recordset("name") + "(id" + customers.recordset("customer_id") +") bought " + customers.recordset("product_name") + "from the " + customers.recordset("department")+ "department on " + customers.recordset("purchase_date") + ".<br />" } customers.recordset.moveNext() } } </script> </head>
<body> <form id="form1"> search for this name: <input type="text" name="text1" /> <br /><br /> <input type="button" value="sarch for mathes" onclick="findmatches()" /> </form> </body> |
Indexof 메소드를 사용하면 사용자가 찾고자 하는 이름과 현재의 이름이 일치하는지 확인할 수 있다
웹 페이지에서 애플릿에 약간의 공간만 허용할 수 있다면, 그 애플릿을 통해 작업의 상태를 표시할 수 있다
|
<head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>searching xml-based databases</title> <xml id="customers" src="../Altova/XMLSpy2010/ch08ex13.xml"></xml>
<script language="javascript"> function findmatches() { var searchFor= form1.text1.value.toLowerCase()
while(!customers.recordset.EOF){ var currentName = new String(customers.recordset("name")) currentName = currentName.toLowerCase() if(currentName.indexOf(searchFor)>=0){ divMessage.innerHTML += customers.recordset("name") + "(id" + customers.recordset("customer_id") +") bought " + customers.recordset("product_name") + "from the " + customers.recordset("department")+ "department on " + customers.recordset("purchase_date") + ".<br />" } customers.recordset.moveNext() } } </script> </head>
<body> <applet code="com.ms.xml.dso.XMLDSO.class" id="customers" width="400" height="50" mayscript="true"> <param name="url" value="ch08ex13.xml" /> </applet>
<form id="form1"> search for this name: <input type="text" name="text1" /> <br /><br /> <input type="button" value="sarch for mathes" onclick="findmatches()" /> </form>
</body> |
출처: xml 입문
'데이터베이스 > XML' 카테고리의 다른 글
| 6 javascript 이해하기 (0) | 2010.12.27 |
|---|