Download presentation
Presentation is loading. Please wait.
Published byByron Williams Modified over 8 years ago
1
USING XML AS A DATA SOURCE
2
Data binding is a process by which information in a data source is stored as an object in computer memory. In this presentation, the data source is an XML document containing information. The Web pages uses placeholders which we will later populate with data from two XML documents.
3
USING XML AS A DATA SOURCE
4
DATA BINDING WITH SEVERAL WEB PAGES
5
FIELDS, RECORDS, AND RECORDSETS Data in a data source is organized by fields, records, and recordsets. A field is an element that contains a single item of information such as an employees last name. A record is a collection of those fields. A recordset is a collection of records.
6
DATA ISLANDS The first step in data binding is to attach the Web page to a recordset. The attached data is called a data island. They can be either external files or code entered into the HTML file. The syntax to create a data island from an external file is: Here, id is the id name assigned to the data island URL is the filename and location of the external XML file
7
DATA ISLANDS For example: This creates a data island named Company attached to Company.xml.
8
DATA ISLANDS To insert a data island directly into the HTML file, use this syntax: xml code
9
DATA ISLANDS Data islands are stored by the XML parser as a Data Source Object (DSO). The DSO takes care of the interaction between the Web page and the data island. Also, program code can be written to control the actions of the DSO such as specifying which records will be displayed in the Web page at any one time.
10
BINDING AN HTML ELEMENT TO A FIELD After the data island has been created, the elements in the XML document need to be bound to the HTML file. The syntax is: Here, tag is the name of the HTML tag, id is the name of the data island, and field is the name of the field in the data source.
11
HTML ELEMENTS THAT SUPPORT DATA BINDING
12
BINDING TO AN XML ATTRIBUTE Attributes are treated by the DSO as fields. If the attribute is part of a record element, it is easy to bind attribute values to a Web page. If the attribute is part of a field element, it is still treated by the DSO as a field element.
13
BINDING TO AN XML ATTRIBUTE The field element containing the attribute becomes a record element. Remember to reference all character data within an element using the $TEXT field. It is a good idea not to use attributes in field elements if you plan to do data binding.
14
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()
15
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.
16
THE DATA SOURCE OBJECT
17
When the user clicks the button, the browser runs the command indicated by the onClick event handler, displaying the last record.
18
TABLE BINDING Using table data binding, each record can be displayed in a different row of a table. The syntax is:
19
TABLE BINDING In the example, id is the name of the data island, field1, field2 are the fields from the recordset.
20
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.
21
TABLE PAGES To specify the page size, add the dataPageSize attribute to the tag: datapagesize=“number” number is the number of records you want displayed in a single page.
22
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: 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.
23
TABLE METHODS AND PROPERTIES
24
To run these commands, add the command to the onClick event handler of a tag. For example, to move to the last page in a data table named “StaffTable”, you enter the attribute: onClick=“productTable.lastPage( )”
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.