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

21
New Perspectives on XML, 2nd Edition Tutorial 9B 1 USING XML AS A DATA SOURCE TUTORIAL 9B

Upload: dortha-green

Post on 04-Jan-2016

236 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

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

USING XML AS A DATA SOURCE

TUTORIAL 9B

Page 2: New Perspectives on XML, 2nd Edition Tutorial 9B1 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()

Page 3: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

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.

Page 4: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

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

THE DATA SOURCE OBJECT

Page 5: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

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( )”>

Page 6: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

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.

Page 7: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

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

ASSIGNING A RECORDSET METHOD

Page 8: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

Practice

• P. 530-531• P. 533

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

Page 9: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

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>

Page 10: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

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.

Page 11: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

Practice

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

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

Page 12: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

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.

Page 13: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

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.

Page 14: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

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.

Page 15: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

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

TABLE METHODS AND PROPERTIES

Page 16: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

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( )”

Page 17: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

Practice

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

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

Page 18: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

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

HIERARCHICAL RECORDSETS

Page 19: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

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>

Page 20: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

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

THE FINAL WEB PAGE

Page 21: New Perspectives on XML, 2nd Edition Tutorial 9B1 USING XML AS A DATA SOURCE TUTORIAL 9B

Practice

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

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