150 likes | 288 Views
This guide explains how to use XML data islands in HTML to create dynamic web applications. By treating XML as a Data Source Object (DSO), it handles symmetric data effectively and supports multiple data islands within a single HTML file. It outlines key functionalities, including defining data islands, mapping XML data to ADO recordsets, and binding individual XML fields to HTML elements. Learn about pagination for large data sets, accessing repeating XML elements, and navigating the DSO recordset with script methods for enhanced interactivity.
E N D
Embedding XML in HTML: Using Data Islands Eugenia Fernandez IUPUI
Internet Explorer 5 Approach • Treats XML as a Data Source Object or DSO, also referred to as a data island • Handles symmetric data best, i.e. data that resembles a relational table • Can use multiple data islands in same HTML file • Each data island requires unique ID
Defining a Data Island • A data island is defined within the <XML> and </XML> HTML tags. • explicitly, by embedding XML data directly • implicitly, by reference to external XML file <XML ID=“xmldso”> <?xml version=“1.0”?>some XML</XML> <XML ID=“xmldso” SRC=“products.xml”></XML>
Mapping XML Data to an ADO Recordset XML data within an XML data island is treated as an ADO recordset. Each main element maps to a record in the ADO recordset, and each child element maps to a field in the record.
ADO Mapping Example <booklist> <book> <title>The Autobiography of Benjamin Franklin</title> <author>Benjamin Franklin</author> <price>8.99</price> </book> <book> <title>The Confidence Man</title> <author>Herman Melville</author> <price>11.99</price> </book></booklist>
Binding Data Islands to HMTL Elements • Individual fields can be bound to HTML tags using the DATASRC and DATAFLD attributes • DATASRC specifies the ID of the XML data island. The ID must be preceded with #. • DATAFLD specifies the XML field from which data is taken. <DIV DATASRC=“#xmldso” DATAFLD=“title”></DIV>
A APPLET BUTTON DIV FRAME IFRAME INPUT (where TYPE = CHECKBOX, HIDDEN, LABEL, PASSWORD, RADIO, TEXT) IMG LABEL MARQUEE SELECT SPAN TABLE TEXTAREA HTML Elements That Support DSO Binding
Displaying Data in HTML Tables • Use a TABLE to display multiple rows of data. • Set the DATASRC in the TABLE tag. • For each TD, include an HTML element and set its DATAFLD attribute • The data binding agent automatically populates multiple rows, for each record in the XML dataset. <TABLE DATASRC=“#xmldso”> <TR> <TD><DIV DATAFLD=“title”></DIV></TD> </TR></TABLE>
Paging the DSO Data • For large XML data islands, DSO allows the data to be displayed in pages. • The size of the page is set through the DATAPAGESIZE attribute in the TABLE tag. <TABLE DATASRC=“#xmldso” DATAPAGESIZE=10>
Accessing Repeating XML Elements • Use a nested table to access repeating XML elements <book> <title>Gourmet Microwave Cooking</title> <price>18.99</price> <author>Charlotte Waves</author> <author>Regina Cooker</author> <author>Mario Gourd</author> </book> <TD> <TABLE DATASRC=“#xmldso” DATAFLD=“author”> <TR><TD><SPAN DATAFLD=“$Text”></SPAN></TD></TR> </TABLE></TD>
Accessing XML Attributes <book genre=“Autobiography”> <title>The Autobiography of Benjamin Franklin</title> <author>Benjamin Franklin</author> <price>8.99</price> </book> <book genre=“Literature”> <title>The Confidence Man</title> <author>Herman Melville</author> <price>11.99</price> </book> • XML attributes are treated as child elements <TD><SPAN DATAFLD=“genre”></SPAN></TD><TD><SPAN DATAFLD =“title”></SPAN></TD>
Navigating the DSO Recordset • You can navigate through your DSO Recordset by adding script to call the ADO move methods: • Move, MoveFirst, MoveLast, MoveNext, MovePrevious • Example xmldso.recordset.MoveNext
Adding Navigation • Add a field to display the data • Add a button to invoke the desired move method. <XML ID=“xmldso” SRC=“books.xml”></XML><FORM> <!-- create field to display the data --> Title: <INPUT TYPE=‘text’ DATASRC=“#xmldso” DATAFLD=“title”> <!-- add a button to step through the XML data --><INPUT TYPE=“button” ID=“btnNext” Value=“Next”></FORM>
Adding Navigation, cont. • Set an onclick event procedure for the button that calls the move command. <HEAD> <script language=“VBScript”>Sub btnNext_onclick() xmldso.recordset.MoveNextEnd Sub</script> </HEAD>
Sources • “Building XML-Based Web Applications” a Microsoft Certified Course.