Wta3 XML Dso

17
WTA Topic 3 : XML Data Source Objects Reference: 1 Subject Incharge Pratidnya S. Hegde Patil Reference: 1. W3Schools 2. http://www.brainbell.com/tutors/XML/XML_Book_B/The_XML_DSO.htm

description

Wta3 XML Dso

Transcript of Wta3 XML Dso

Page 1: Wta3 XML Dso

WTA Topic 3 :

XML Data Source Objects

Reference:

1

Subject Incharge

Pratidnya S. Hegde Patil

Reference:1. W3Schools2. http://www.brainbell.com/tutors/XML/XML_Book_B/The_XML_DSO.htm

Page 2: Wta3 XML Dso

XML Data Source

Objects (DSO)

Deals with the usage of an XML

2

Deals with the usage of an XML document as a data source in

much the same way that Access or Oracle is used.

Page 3: Wta3 XML Dso

XML DSO

� The XML DSO allows you to bring data over to the client as XML and then manipulate the XML data directly on the client.

Page 4: Wta3 XML Dso

DSO

� DSO is an object that operates like a database on the client side. An instance of it has to be created for use, which gives an effect of a miniature data miniature data engine embedded in the HTMLengine embedded in the HTML.

4

� XML DSO is used to bind data of XML document to controls on an HTML page.

� It lets you access the data without walking access the data without walking through the document treethrough the document tree.

Page 5: Wta3 XML Dso

XML element

� The XML DSO allows you to work with XML datathat is embedded directly in your HTML code.This embeddedembedded XMLXML codecode createscreates datadata islandsislands.

� To create a data island, you will use the newHTML xmlxml element.HTML xmlxml element.

� The DSO will find the data located in the xmlelement and use it as a data island.

Page 6: Wta3 XML Dso

XML element

� The xml element includes an idid attributethat will be used to reference the dataisland. The xml element looks as follows:

<xml id="orderDSO"> <!--XML data goes here --> </xml>

� You can also reference XML data in an external XML document by using the xmlelement and the srcsrc attribute as follows:

<xml id="orderDSO" src="NorthwindOrder.xml"></xml>

Page 7: Wta3 XML Dso

Binding HTML Elements to XML Data

Using the XML DSO

� Once you have created a reference to an XML data source using the xml element, you can bind this data to some of the you can bind this data to some of the HTML elements in a documentHTML elements in a document.

� With some of the elements, you can display the content that is within the element as either text or as HTMLtext or as HTML.

Page 8: Wta3 XML Dso

DHTML tags used for XML DSO

<STYLE><STYLE> Style tag used to embed style information within a document. The style tag should always include the TYPE declaration.

IDID ID attribute has an unique value over the document. The ID name declaration should be preceded by a #, in the <STYLE> declaration.

SPANSPAN Extracts a section of the document with the styles applied.

8

SPANSPAN Extracts a section of the document with the styles applied. Used within the DIV tag.

DIVDIV DIV tag is the actual container of the data.

DATASRCDATASRC DATASRC attribute pertains to databound objects. The ID of the DSO instance on the page is specified by the DATASRC attribute.

DATAFLDDATAFLD DATAFLD attribute specifies the name of the column to which the HTML element is bound. This attribute is always used along with the DATASRC attribute.

Page 9: Wta3 XML Dso

<html>

<xml src="catalogs.xml" id="CatalogDSO"></xml>

<body>

<table border="2" width="100%" datasrc="#CatalogDSO" cellpadding="5">

<thead>

<th>Book Name</th>

<th>Author Name</th>

<th>ISBN</th>

<th>Publisher Name</th>

<th>Pages</th>

<th>Price</th>

The data is bound to a multivalue such as a table element rather than several single-valued elements such as SPAN tags.

first.html

Ex1:Accessing all records together

9

<th>Price</th>

</thead>

<tbody>

<tr>

<td valign="top"><span datafld="BOOKNAME"></span></td>

<td valign="top"><span datafld="AUTHORNAME"></span></td>

<td valign="top"><span datafld="ISBN"></span></td>

<td valign="top"><span datafld="PUBLISHER"></span></td>

<td valign="top"><span datafld="PAGES"></span></td>

<td valign="top"><span datafld="PRICE"></span></td>

</tr>

</tbody>

</table>

</body>

</html>

catalogs.xml

catalogs.dtd

Page 10: Wta3 XML Dso

<!ELEMENT CATALOGS (BOOK)*><!ELEMENT BOOK (BOOKNAME, AUTHORNAME,

ISBN, PUBLISHER, PAGES?, PRICE)><!ELEMENT BOOKNAME (#PCDATA)><!ELEMENT AUTHORNAME (#PCDATA)><!ELEMENT ISBN (#PCDATA)><!ELEMENT PUBLISHER (#PCDATA)><!ELEMENT PAGES (#PCDATA)><!ELEMENT PRICE (#PCDATA)>

<?xml version="1.0"?><!DOCTYPE CATALOGS SYSTEM "catalogs.dtd"><CATALOGS><BOOK><BOOKNAME>Oracle 8i</BOOKNAME>

<BOOK><BOOKNAME>XML to code</BOOKNAME><AUTHORNAME>Jesse Liberty</AUTHORNAME><ISBN>1-861000-95-2</ISBN><PUBLISHER>Wrox Press</PUBLISHER>

catalogs.dtd

catalogs.xml

<BOOKNAME>Oracle 8i</BOOKNAME><AUTHORNAME>Richard

Gosling</AUTHORNAME><ISBN>0-07-913702-4</ISBN><PUBLISHER>BPB Publications</PUBLISHER><PAGES>393</PAGES><PRICE>410.00</PRICE></BOOK>

<BOOK><BOOKNAME>XML in Action</BOOKNAME><AUTHORNAME>William J.

Pardi</AUTHORNAME><ISBN>0-07-914702-9</ISBN><PUBLISHER>Microsoft Press</PUBLISHER><PAGES>492</PAGES><PRICE>470.00</PRICE></BOOK>

<PUBLISHER>Wrox Press</PUBLISHER><PAGES>393</PAGES><PRICE>560.00</PRICE></BOOK>

<BOOK><BOOKNAME>Java Unleashed</BOOKNAME><AUTHORNAME>James Spencer</AUTHORNAME><ISBN>0-7456-0964-1</ISBN><PUBLISHER>Techmedia Publications</PUBLISHER><PAGES>491</PAGES><PRICE>670.00</PRICE></BOOK></CATALOGS>

Page 11: Wta3 XML Dso

Accessing one record at a time

(Properties & Methods of Recordset object)

Property Action

moveFirst() Moves the iterator to the first record.

moveLast() Moves the iterator to the last record.

moveNext() Moves the iterator to the next record.

movePrevious() Moves the iterator to the previous record.

EOF Property of recordset that is true if the iterator is at

11

EOF Property of recordset that is true if the iterator is at the end of file.

BOF Property of recordset that is true if the iterator is at the file start.

move(integer) Moves the iterator to the record number passed.

Delete() Deletes the current recordset.

AddNew() Adds a new record to the end of the file.

cancelUpdate Cancels all the updates to the recordset since it was loaded.

Fields() When passed either the name of the field or an index number, returns the field’s value.

Page 12: Wta3 XML Dso

Example : Accessing one record at a time

� Loads an XML document into the XML DSO and bindsvarious data elements to SPAN elements in the HTML page.

� A SPAN element appears for every element to be displayedthat corresponds to an element in the XML document.

12

� The DATASRC attribute of the SPAN tag specifies the DSOthat has to be used (a pound sign followed by the name ofthe DSO) and the DATAFLD attribute specifies the elementof the XML document that is supplying the data.

� The HTML page contains buttons that are tied torecordset.moveFirst(),recordset.movePrevious(),recordset.moveNext(),recordset.moveLast() methods of DSO.

Page 13: Wta3 XML Dso

Ex2:Accessing one record at a time

through buttons

13

Page 14: Wta3 XML Dso

Accessing one record at a time<html>

<body><xml src="catalogs.xml" id="CatalogsDSO"></xml>

<table border="1"><tr><td>Book Name: </td><td><span datasrc="#CatalogsDSO"

datafld="BOOKNAME"></span> </td></tr><tr><td>Author Name: </td><td><span datasrc="#CatalogsDSO"

datafld="AUTHORNAME"></span></td>

<!-- navigation buttons --><table><tr>

<td><input id="cmdMoveFirst" name="cmdMoveFirst"type="button" value="Move First” onClick="CatalogsDSO.recordset.moveFirst();"></input></td>

<td><input id="cmdMovePrevious“ name="cmdMovePrevious"type="button" value="Move Previous"onClick="CatalogsDSO.recordset.movePrevious();if (CatalogsDSO.recordset.BOF) {

buttons.html

14

datafld="AUTHORNAME"></span></td></tr><tr><td>ISBN: </td><td><span datasrc="#CatalogsDSO“

datafld="ISBN"></span></td></tr><tr><td>Publisher: </td><td><span datasrc="#CatalogsDSO"

datafld="PUBLISHER"></span></td></tr><tr><td>Pages: </td><td><span datasrc="#CatalogsDSO"

datafld="PAGES"></span></td></tr><tr><td>Price: </td><td><span datasrc="#CatalogsDSO"

datafld="PRICE"></span></td></tr></table>

onClick="CatalogsDSO.recordset.movePrevious();if (CatalogsDSO.recordset.BOF) {CatalogsDSO.recordset.moveFirst();}"></input></td>

<td><input id="cmdMoveNext" name="cmdMoveNext"type="button" value="Move Next"onClick="CatalogsDSO.recordset.moveNext();if (CatalogsDSO.recordset.EOF) {CatalogsDSO.recordset.moveLast();}"></input></td>

<td><input id="cmdMoveLast" name="cmdMoveLast"type="button" value="Move Last“ onClick="CatalogsDSO.recordset.moveLast();"></input></td>

</tr></table></body></html>

catalogs.xml

catalogs.dtd

Page 15: Wta3 XML Dso

Ex3:All record display with inner

table

15

Page 16: Wta3 XML Dso

<html><xml src="NorthwindPO2.xml"

id="NorthwindDSO"></xml><body>

<table border="2" width="100%" datasrc="#NorthwindDSO" cellpadding="5">

<thead><th>Line Item</th><th>Details</th>

</thead><tbody>

<tbody><tr><td valign="top"><span datafld="partno"></span></td><td valign="top"><span datafld="qty"></span></td><td valign="top"><span datafld="uom"></span></td><td valign="top"><span datafld="unitprice"></span></td><td valign="top">

All record display with inner tableinnertable.html

16

<tbody><td valign="top"><span

datafld="line"></span></td><td><table border="1" width="100%"

datasrc="#NorthwindDSO"datafld="Item" cellpadding="5"><thead>

<th>Part No</th><th>Quantity</th><th>UOM</th><th>Unit Price</th><th>Discount</th><th>Total</th>

</thead>

<td valign="top"><span datafld="discount"></span></td><td valign="top"><span datafld="totalAmount“></span></td>

</tr></tbody></table></td></tbody></table></body></html> NorthwindPO2.xml

NorthwindPO2.dtd

Page 17: Wta3 XML Dso

NorthwindPO2.xml<?xml version="1.0" standalone="no" ?>

<!DOCTYPE po SYSTEM "NorthwindPO2.dtd">

<po>

<POLine>

<POLine>

<line>102</line>

<Item>

<partno>pc2010</partno>

<!ELEMENT po (POLine+)>

<!ELEMENT POLine (line , Item+)><!ELEMENT Item (partno , qty , uom , unitPrice , discount , totalAmount)><!ELEMENT line (#PCDATA)><!ELEMENT partno (#PCDATA)><!ELEMENT qty (#PCDATA)><!ELEMENT uom (#PCDATA)><!ELEMENT unitPrice (#PCDATA)><!ELEMENT discount (#PCDATA)><!ELEMENT totalAmount (#PCDATA)>

NorthwindPO2

.dtd

17

<line>101</line>

<Item>

<partno>pc1010</partno>

<qty>200</qty>

<uom>EACH</uom>

<unitPrice>800.00</unitPrice>

<discount>10</discount>

<totalAmount>144000.00</totalAmount>

</Item>

<Item>

<partno>monitor17</partno>

<qty>200</qty>

<uom>EACH</uom>

<unitPrice>300.00</unitPrice>

<discount>20</discount>

<totalAmount>48000.00</totalAmount>

</Item>

</POLine>

<partno>pc2010</partno>

<qty>100</qty>

<uom>EACH</uom>

<unitPrice>1200.00</unitPrice>

<discount>10</discount>

<totalAmount>108000.00</totalAmount>

</Item>

<Item>

<partno>monitor19</partno>

<qty>100</qty>

<uom>EACH</uom>

<unitPrice>500.00</unitPrice>

<discount>10</discount>

<totalAmount>45000.00</totalAmount>

</Item>

</POLine>

</po>