new perspectives on xml, 2nd edition tutorial 9b1 using xml as a data source tutorial 9b

Post on 04-Jan-2016

228 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

New Perspectives on XML, 2nd Edition Tutorial 9B 1

USING XML AS A DATA SOURCE

TUTORIAL 9B

New Perspectives on XML, 2nd Edition Tutorial 9B 2

THE DATA SOURCE OBJECT

• ActiveX Data Objects (ADO) is a data-access technology developed by Microsoft. ADO allows you to work with the Data Source Object by applying a method or by changing one of the properties of the DSO.

• The syntax for applying a method is:

id.recordset.method()

New Perspectives on XML, 2nd Edition Tutorial 9B 3

THE DATA SOURCE OBJECT

• Here, id is the name of the data island in the Web document and method is the name of the method supported by ADO.

• There are several methods that can be applied to DSOs.

New Perspectives on XML, 2nd Edition Tutorial 9B 4

THE DATA SOURCE OBJECT

New Perspectives on XML, 2nd Edition Tutorial 9B 5

THE DATA SOURCE OBJECT

• For example, if you want to display the last record in a DSO whose id is “staffInfo”, run the following method:

staffInfo.recordset.moveLast( )

• The simplest way to run a method is to assign the method to the onClick event handler of a <button> as shown below: <button onClick=“staffInfo.recordset.moveLast( )”>

New Perspectives on XML, 2nd Edition Tutorial 9B 6

THE DATA SOURCE OBJECT

• When the user clicks the button, the browser runs the command indicated by the onClick event handler, displaying the last record.

New Perspectives on XML, 2nd Edition Tutorial 9B 7

ASSIGNING A RECORDSET METHOD

Practice

• P. 530-531• P. 533

New Perspectives on XML, 2nd Edition Tutorial 9B 8

New Perspectives on XML, 2nd Edition Tutorial 9B 9

TABLE BINDING

• Using table data binding, each record can be displayed in a different row of a table. The syntax is:

<table datasrc=“#id”> <tr> <td><span datafld=“field1”></span></td> <td><span datafld=“field2”></span></td> </tr> </table>

New Perspectives on XML, 2nd Edition Tutorial 9B 10

TABLE BINDING

• In the example, id is the name of the data island, field1, field2 are the fields from the recordset.

Practice

• P. 534-535• P. 536-537

New Perspectives on XML, 2nd Edition Tutorial 9B 11

New Perspectives on XML, 2nd Edition Tutorial 9B 12

TABLE PAGES

• As you add more records to your XML document, a table can become long and unwieldy. One way to fix this is to give the user the option of limiting the number of records displayed at any one time.

• The user can then move forward of backward that number of records at a time. This is called paging.

New Perspectives on XML, 2nd Edition Tutorial 9B 13

TABLE PAGES

• To specify the page size, add the dataPageSize attribute to the <table> tag:

datapagesize=“number”

• number is the number of records you want displayed in a single page.

New Perspectives on XML, 2nd Edition Tutorial 9B 14

NAVIGATING A TABLE PAGE

• A unique identifier must be assigned to a table using the ID attribute before writing a command to navigate a table page. The syntax to do this is:

<table id=“id”>

• Here, id is the name you assign to the table object.

• This is needed because the commands to navigate the table pages act on the table itself not the recordset.

New Perspectives on XML, 2nd Edition Tutorial 9B 15

TABLE METHODS AND PROPERTIES

New Perspectives on XML, 2nd Edition Tutorial 9B 16

TABLE METHODS AND PROPERTIES

• To run these commands, add the command to the onClick event handler of a <button> tag. For example, to move to the last page in a data table named “StaffTable”, you enter the attribute:

onClick=“staffTable.lastPage( )”

Practice

• P. 538-539• P. 540• P. 541

New Perspectives on XML, 2nd Edition Tutorial 9B 17

New Perspectives on XML, 2nd Edition Tutorial 9B 18

HIERARCHICAL RECORDSETS

New Perspectives on XML, 2nd Edition Tutorial 9B 19

HIERARCHICAL RECORDSETS

• To bind the Employee fields in the previous slide to a table, you create a table as follows:

<table datasrc=“#staffInfo” datafld=“employee”> <tr> <td><span datafld=“name”></span></td> <td><span datafld=“position”></span></td> <td><span datafld=“phone”></span></td> … </tr> </table>

New Perspectives on XML, 2nd Edition Tutorial 9B 20

THE FINAL WEB PAGE

Practice

• P. 543• P. 545-547• P. 547-548• P. 549

New Perspectives on XML, 2nd Edition Tutorial 9B 21

top related