[XML Embedded in HTML][CSS/XSL][Processing
Instructions]
XML in Data Islands
With Internet Explorer 5.0, XML can be embedded within HTML pages in
Data Islands.
XML Embedded in HTML
The unofficial <xml> tag is used to embed XML data
within HTML.
XML data can be embedded directly in an HTML page like this:
<xml id="note">
<note>
<to>T
ove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
</xml>
Or a separate XML file can be embedded
like this:
<xml id="note" src="note.xml">
</xml>
Note that the <xml> tag is an HTML element, not an XML element.
Data Binding
Data Islands can be bound to HTML elements (like HTML
tables).
In the example below, an XML Data Island with an ID "cdcat"
is loaded from an external XML file. An HTML table is bound to the Data
Island with a data source attribute, and finally the tabledata elements
are bound to the XML data with a data field attribute inside a span.
<html>
<body>
<xml id="cdcat" src="cd_catalog.xml"></xml>
<table border="1" datasrc="#cdcat">
<tr>
<td><span datafld="artist"></span></td>
<td><span datafld="title"></span></td>
</tr>
</table>
</body>
</html>
The Microsoft XML Parser
To read and update - create and manipulate - an XML document, you need
an XML parser
Using the XML parser
The Microsoft XML parser comes with Microsoft Internet
Explorer 5.0.
Once you have installed IE 5.0, the parser is available to scripts, both
inside HTML documents, and inside ASP files. The parser features a language-neutral
programming model that supports:
JavaScript, VBScript, Perl, VB, Java, C++ and more
W3C XML 1.0 and XML DOM
DTD and validation
If you are using JavaScript in IE 5.0, you can create an XML document
object with the following code:
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
If you are using VBScript you create the XML document object with the
following code:
set xmlDoc = CreateObject("Microsoft.XMLDOM")
If you are using VBScript in an Active Server Page (ASP), you can use
the following code:
set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
Loading an XML file into the parser
XML files can be loaded into the parser using script
code.
The following code loads an XML document (note.xml) into the XML parser:
<script language="JavaScript">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note.xml")
// ....... processing the document goes here
</script>
The first line of this script creates an instance of the Microsoft XML
parser.
The second line turns off asynchronized loading, to make sure that the
parser will not continue execution before the document is fully loaded.
The third line tells the parser to load an XML document called note.xml.
Loading pure XML text into the parser
XML text can also be loaded from a text string.
The following code loads a text string into the XML parser:
<script language="JavaScript">
var text="<note>"
text=text+"<to>Tove</to><from>Jani</from>"
text=text+"<heading>Reminder</heading>"
text=text+"<body>Don't forget
me this weekend!</body>"
text=text+"</note>"
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.loadXML(text)
// ....... processing the document goes
here
</script>
Note that the "loadXML" method (instead of the "load"
method) is used to load a text string.
Displaying XML with JavaScript
To display XML you can use JavaScript.
JavaScript (or VBScript) can be used to import data from an XML file,
and display the XML data inside an HTML page.
XML in Real Life
Some real-life examples how XML can be used to carry information.
Example: XML News
XMLNews is a specification for exchanging news and other
information.
Using such a standard, makes it easier for both news producers and news
consumers to produce, receive, and archive any kind of news information
across different hardware, software and programming languages.
An example XML News document:
<?xml version="1.0"?>
<nitf>
<head>
<title>Colombia Earthquake</title>
</head>
<body>
<body.head>
<headline>
<hl1>143 Dead in Colombia Earthquake</hl1>
</headline>
<byline>
<bytag>By Jared Kotler, Associated Press Writer</bytag>
</byline>
<dateline>
<location>Bogota, Colombia</location>
<story.date>Monday January 25 1999 7:28 ET</story.date>
</dateline>
</body.head>
</body>
</nitf>
Authoring XML Data Islands
What is an XML data island?
A data island is an XML document that exists within an HTML page. It
allows you to script against the XML document without having to load it
through script or through the <OBJECT> tag. Almost anything that
can be in a well-formed XML document can be inside a data island.
Displaying the XMl from within the HTML gives you the best of two words:
data storage in an XML document, with its flexible way of structuring
data and labeling every piece of information, plus the established formatting
richness and dynamic portability of HTML.
The XML element marks the beginning of the data island, and its ID attribute
provides a name you can use to reference the data island.
The XML for a data island can be either inline:
<XML ID="XMLID">
<customer>
<name>Mark Hanson</name>
<custID>81422</custID>
</customer>
</XML>
or referenced through a SRC attribute
on the XML tag:
<XML ID="XMLID" SRC="customer.xml"></XML>
You can also use the SCRIPT tag to create
a data island:
<SCRIPT LANGUAGE="xml" ID="XMLID">
<customer>
<name>Mark Hanson</name>
<custID>81422</custID>
</customer>
</SCRIPT>
The Main Steps
1. Linking the XML document to the HTML page in which you want to display
the XML data.
a. <XML ID=”dsoBook” src=”Book.xml”></xml>
b. Binding HTML elemtns to XML elements
<?xml version="1.0"?>
<!-- File Name: Book.xml -->
<BOOK>
<TITLE>The Adventures of Huckleberry Finn</TITLE>
<AUTHOR>Mark Twain</AUTHOR>
<BINDING>mass market paperback</BINDING>
<PAGES>298</PAGES>
<PRICE>$5.49</PRICE>
</BOOK>
<!-- File Name: Book.htm -->
<HTML>
<HEAD>
<TITLE>Book Description</TITLE>
</HEAD>
<BODY>
<XML ID="dsoBook" SRC="Book.xml"></XML>
<H2>Book Description</H2>
<SPAN STYLE="font-style:italic">Title: </SPAN>
<SPAN STYLE="font-weight:bold" DATASRC="#dsoBook"
DATAFLD="TITLE"></SPAN>
<BR>
<SPAN STYLE="font-style:italic">Author: </SPAN>
<SPAN DATASRC="#dsoBook" DATAFLD="AUTHOR"></SPAN>
<BR>
<SPAN STYLE="font-style:italic">Binding type: </SPAN>
<SPAN DATASRC="#dsoBook" DATAFLD="BINDING"></SPAN>
<BR>
<SPAN STYLE="font-style:italic">Number of pages: </SPAN>
<SPAN DATASRC="#dsoBook" DATAFLD="PAGES"></SPAN>
<BR>
<SPAN STYLE="font-style:italic">Price: </SPAN>
<SPAN DATASRC="#dsoBook" DATAFLD="PRICE"></SPAN>
</BODY>
</HTML>
How the XML Data is Stored
IE 5 creates a programming object called DSO (data source object) which
stores or caches the XML data and provide access tp this data. The DSO
stores the XML data as recordser. When you bind an HTML element to an
XML element, the DSO automatically supplies the value of the XML element
and handles the details.
The DSO also lets you to directly access and maipulate the stored recordset
through a collection of methods, properties and events.
You can bind your HTML elements to XML elements by using
1. Table data binding
2. Single record data binding
Table Data binding:Using the inventory XML
<!-- File Name: Inventory Table.htm -->
<HTML>
<HEAD>
<TITLE>Book Inventory</TITLE>
</HEAD>
<BODY>
<XML ID="dsoInventory" SRC="Inventory.xml"></XML>
<H2>Book Inventory</H2>
<TABLE DATASRC="#dsoInventory" BORDER="1" CELLPADDING="5">
<THEAD>
<TH>Title</TH>
<TH>Author</TH>
<TH>Binding</TH>
<TH>Pages</TH>
<TH>Price</TH>
</THEAD>
<TR ALIGN="center">
<TD><SPAN DATAFLD="TITLE"
STYLE="font-style:italic"></SPAN></TD>
<TD><SPAN DATAFLD="AUTHOR"></SPAN></TD>
<TD><SPAN DATAFLD="BINDING"></SPAN></TD>
<TD><SPAN DATAFLD="PAGES"></SPAN></TD>
<TD><SPAN DATAFLD="PRICE"></SPAN></TD>
</TR>
</TABLE>
</BODY>
</HTML>
You can add the following to navigate through the recordsets
Where datapagesize means home many records at a time you want to see
<!-- File Name: Inventory Big Table.htm -->
<HTML>
<HEAD>
<TITLE>Book Inventory</TITLE>
</HEAD>
<BODY>
<XML ID="dsoInventory" SRC="Inventory Big.xml"></XML>
<H2>Book Inventory</H2>
<BUTTON ONCLICK="InventoryTable.firstPage()">
|< First Page
</BUTTON>
<BUTTON ONCLICK="InventoryTable.previousPage()">
< Previous Page
</BUTTON>
<BUTTON ONCLICK="InventoryTable.nextPage()">
Next Page >
</BUTTON>
<BUTTON ONCLICK="InventoryTable.lastPage()">
Last Page >|
</BUTTON>
<p>
<TABLE ID="InventoryTable" DATASRC="#dsoInventory"
DATAPAGESIZE="5" BORDER="1" CELLPADDING="5">
<THEAD>
<TH>Title</TH>
<TH>Author</TH>
<TH>Binding</TH>
<TH>Pages</TH>
<TH>Price</TH>
</THEAD>
<TR ALIGN="center">
<TD><SPAN DATAFLD="TITLE"
STYLE="font-style:italic"></SPAN></TD>
<TD><SPAN DATAFLD="AUTHOR"></SPAN></TD>
<TD><SPAN DATAFLD="BINDING"></SPAN></TD>
<TD><SPAN DATAFLD="PAGES"></SPAN></TD>
<TD><SPAN DATAFLD="PRICE"></SPAN></TD>
</TR>
</TABLE>
</BODY>
</HTML>
Using a Nested Table to Display a Hierarchical Recordset
In the previous example you saw how to show a simple XML document
structured as a simple recordset, where each recor contains a fixed set
of fields, all of which can stor character only.
In an hierarchical record set each record can contain in addition to
the ficed set of fields, a variable number of occurrences (sero or more)
of a nested record.
Suppose you had
<?xml version="1.0"?>
<!-- File Name: Inventory Hierarchy.xml -->
<INVENTORY>
<CATEGORY>
<CATNAME>Renaissance</CATNAME>
<BOOK>
<TITLE>The Blazing World</TITLE>
<AUTHOR>Margaret Cavendish</AUTHOR>
<BINDING>trade paperback</BINDING>
<PAGES>225</PAGES>
<PRICE>$8.79</PRICE>
</BOOK>
</CATEGORY>
<CATEGORY>
<CATNAME>18th Century</CATNAME>
<BOOK>
<TITLE>Gulliver's Travels</TITLE>
<AUTHOR>Jonathan Swift</AUTHOR>
<BINDING>hardcover</BINDING>
<PAGES>324</PAGES>
<PRICE>$11.89</PRICE>
</BOOK>
<BOOK>
<TITLE>The History of Tom Jones: A Foundling</TITLE>
<AUTHOR>Henry Fielding</AUTHOR>
<BINDING>hardcover</BINDING>
<PAGES>438</PAGES>
<PRICE>$16.95</PRICE>
</BOOK>
</CATEGORY>
<CATEGORY>
<CATNAME>19th Century</CATNAME>
<BOOK>
<TITLE>Dracula</TITLE>
<AUTHOR>Bram Stoker</AUTHOR>
<BINDING>hardcover</BINDING>
<PAGES>395</PAGES>
<PRICE>$17.95</PRICE>
</BOOK>
<BOOK>
<TITLE>Great Expectations</TITLE>
<AUTHOR>Charles Dickens</AUTHOR>
<BINDING>mass market paperback</BINDING>
<PAGES>639</PAGES>
<PRICE>$6.95</PRICE>
</BOOK>
</CATEGORY>
</INVENTORY>
To manipulate this
<!-- File Name: Inventory Hierarchy.htm -->
<HTML>
<HEAD>
<TITLE>Inventory of Classic English Literature</TITLE>
</HEAD>
<BODY>
<XML ID="dsoInventory" SRC="Inventory Hierarchy.xml"></XML>
<TABLE DATASRC="#dsoInventory" BORDER="1">
<THEAD>
<TH>Classic English Literature</TH>
</THEAD>
<TR>
<TD><SPAN DATAFLD="CATNAME"></SPAN></TD>
</TR>
<TR>
<TD>
<TABLE DATASRC="#dsoInventory" DATAFLD="BOOK"
BORDER="0" CELLSPACING="10">
<THEAD>
<TH>Title</TH>
<TH>Author</TH>
<TH>Binding</TH>
<TH>Pages</TH>
<TH>Price</TH>
</THEAD>
<TR ALIGN="CENTER">
<TD><SPAN DATAFLD="TITLE"
STYLE="font-style:italic"></SPAN></TD>
<TD><SPAN DATAFLD="AUTHOR"></SPAN></TD>
<TD><SPAN DATAFLD="BINDING"></SPAN></TD>
<TD><SPAN DATAFLD="PAGES"></SPAN></TD>
<TD><SPAN DATAFLD="PRICE"></SPAN></TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
For a Single_record Data binding
<!-- File Name: Inventory Single.htm -->
<HTML>
<HEAD>
<TITLE>Book Inventory</TITLE>
</HEAD>
<BODY>
<XML ID="dsoInventory" SRC="Inventory Big.xml"></XML>
<H2>Book Description</H2>
<SPAN STYLE="font-style:italic">Title: </SPAN>
<SPAN DATASRC="#dsoInventory" DATAFLD="TITLE"
STYLE="font-weight:bold"></SPAN>
<BR>
<SPAN STYLE="font-style:italic">Author: </SPAN>
<SPAN DATASRC="#dsoInventory" DATAFLD="AUTHOR"></SPAN>
<BR>
<SPAN STYLE="font-style:italic">Binding type: </SPAN>
<SPAN DATASRC="#dsoInventory" DATAFLD="BINDING"></SPAN>
<BR>
<SPAN STYLE="font-style:italic">Number of pages: </SPAN>
<SPAN DATASRC="#dsoInventory" DATAFLD="PAGES"></SPAN>
<BR>
<SPAN STYLE="font-style:italic">Price: </SPAN>
<SPAN DATASRC="#dsoInventory" DATAFLD="PRICE"></SPAN>
<HR>
<BUTTON ONCLICK="dsoInventory.recordset.movefirst()">
|< First
</BUTTON>
<BUTTON ONCLICK="dsoInventory.recordset.moveprevious();
if (dsoInventory.recordset.BOF)
dsoInventory.recordset.movenext()">
lt; Bac
/BUTTON>
BUTTON ONCLICK="dsoInventory.recordset.movenext();
if (dsoInventory.recordset.EOF)
dsoInventory.recordset.moveprevious()">
Forward >
</BUTTON>
<BUTTON ONCLICK="dsoInventory.recordset.movelast()">
Last >|
</BUTTON>
</BODY>
</HTML>
Other Binding elements
- Here you will learn how to bind other HTML elements to XML fields
- How to render HTML Markup contained in XML fields
- How to update the cached XML data
- In the following table you can see all of the HTML elements you can
use for single record binding (all except the table element)
HTML ELEMENT
PURPOSE
BOUND PROPERTY OF THE ELEMENT THAT IS BOUND TO THE XML FIELD
WHETHER THE ELEMENT CAN RENDER ANY html MARKUP CONTAINED IN THE XML FIELD
IT IS BOUND TO
CAN UPDATE THE CONTENTS OF THE XML FIELDS
A
ACHOR ELEMENT
Href
NO
NO
APPLET
JAVA APPLET
Paral
NO
Yes
BUTTON
BUTTON CONTROL
InnerHTML and innerText
Yes
NO
DIV
USED TO FORMAT A DIVISION OF A DOCUMENT
InnerHTML and innerText
Yes
NO
FRAME
Src
NO
NO
IFRAME
CONTAINS AN INLINE FLOATING FRAME
Src
NO
NO
IMG
Src
NO
NO
INPUT TYPE=CHECKBOX
Checked
NO
Yes
INPUT TYPE=HIDDEN
Value
NO
Yes
INPUT TYPE=PASSWORD
Value
NO
Yes
INPUT TYPE=RADIO
Checked
NO
Yes
INPUT TYPE=TEXT
Value
NO
Yes
LABEL
TEXT LABEL
Src
Yes
NO
MARQUE
SCROLLING TEXT
Src
Yes
NO
SELECT
Text property of the selected list item
NO
Yes
SPAN
Src
Yes
NO
TEXTAREA
Value
NO
Yes
Yes
All of the fields that have an inner text property, sets the text that
the element displays, and is bound to the XML field
The innerHTML property sets or retrieves the entire content of the element,
including anyHTML markup
<A datasrc=”#dsoInventory” DATAFLD=”REVIEWS”>
Click here for reviews
</A>
With a bound checkbox type the checked propert is bound to the XML field
<INPUT TYPE=”CHECKBOX” DATASRC=”#dsoInventory”
DATAFLD=”INSTOCK”>
Whenever the INSTOCK field contains anyother text except 0 or false the
checkbox is checked.
In the IMG element the src is bound to the XML field.
<?xml version="1.0"?>
<!-- File Name: Inventory Image.xml -->
<INVENTORY>
<BOOK>
<COVERIMAGE>Moby.bmp</COVERIMAGE>
<TITLE>Moby-Dick</TITLE>
<AUTHOR>Herman Melville</AUTHOR>
<BINDING>hardcover</BINDING>
<PAGES>724</PAGES>
<PRICE>$9.95</PRICE>
</BOOK>
</INVENTORY>
<!-- File Name: Inventory Image Table.htm -->
<HTML>
<HEAD>
<TITLE>Book Inventory</TITLE>
</HEAD>
<BODY>
<XML ID="dsoInventory" SRC="Inventory Image.xml"></XML>
<H2>Book Inventory</H2>
<TABLE DATASRC="#dsoInventory" BORDER="1" CELLPADDING="5">
<THEAD>
<TH>Cover</TH>
<TH>Title</TH>
<TH>Author</TH>
<TH>Binding</TH>
<TH>Pages</TH>
<TH>Price</TH>
</THEAD>
<TR ALIGN="center">
<TD><IMG DATAFLD="COVERIMAGE"></TD>
<TD><SPAN DATAFLD="TITLE"
STYLE="font-style:italic"></SPAN></TD>
<TD><SPAN DATAFLD="AUTHOR"></SPAN></TD>
<TD><SPAN DATAFLD="BINDING"></SPAN></TD>
<TD><SPAN DATAFLD="PAGES"></SPAN></TD>
<TD><SPAN DATAFLD="PRICE"></SPAN></TD>
</TR>
</TABLE>
</BODY>
</HTML>
Rendering HTML
By default if an XML field’s character data happens to include HTML markup,
the HTML element bound to that field treats and displays the markup characters
as literal text.
If you have
<SPAN DATASRC=”#dsoInventroy” DATAFLD=”AUTHOR-BIO”></SPAN>
and the XML field was like
<AUTHOR-BIO>kjsfhjsfhjkd <I>sjdfksdjfh<I><?AUTHOR_BIO>
THE <I> wouldn’t be treated as HTML but rather as literal text.
With some HTML elements such as SPANs you can assign DATAFORMATS attribute
“HTML” to cause the browser to process any HTML tags.
Updating the Cached XML Data
The XML DSO allows you to modufy the XML data in several ways. These
techniques only modify the copy of the XML data that the DSO has temporarily
cached in memory, not the original XML document on the server.
You can also have methods to add or remove entire record from the cached
record set
AddNew dsoInventory.recordset.addNew()
Delete dsoInventory.recordset.delete()
CancelUpdate dsoInventory.recordset.cancelUpdate()
Using DTD with Data Binding
Create a valid DTD for the following example
<?xml version="1.0"?>
<!-- File Name: Inventory Hierarchy Valid.xml -->
<!DOCTYPE INVENTORY
[
<!ELEMENT INVENTORY (CATEGORY*)>
<!ELEMENT CATEGORY (CATNAME, BOOK*)>
<!ELEMENT CATNAME (#PCDATA)>
<!ELEMENT BOOK (TITLE, AUTHOR, BINDING, PAGES, PRICE)>
<!ELEMENT TITLE (#PCDATA)><
!ELEMENT AUTHOR (#PCDATA)>
<!ELEMENT BINDING (#PCDATA)>
<!ELEMENT PAGES (#PCDATA)>
<!ELEMENT PRICE (#PCDATA)>
]
>
<INVENTORY>
<CATEGORY>
<CATNAME>Middle Ages</CATNAME>
<BOOK>
<TITLE>The Canterbury Tales</TITLE>
<AUTHOR>Geoffrey Chaucer</AUTHOR>
<BINDING>hardcover</BINDING>
<PAGES>692</PAGES>
<PRICE>$18.95</PRICE>
</BOOK>
<BOOK>
<TITLE>Piers Plowman</TITLE>
<AUTHOR>William Langland</AUTHOR>
<BINDING>trade paperback</BINDING>
<PAGES>385</PAGES>
<PRICE>$10.95</PRICE>
</BOOK>
</CATEGORY>
</INVENTORY>
<
<!-- File Name: Inventory Hierarchy Valid.htm -->
<HTML>
<HEAD>
<TITLE>Inventory of Classic English Literature</TITLE>
</HEAD>
<BODY>
<XML ID="dsoInventory" SRC="Inventory Hierarchy Valid.xml">
</XML>
<TABLE DATASRC="#dsoInventory" BORDER="1">
<THEAD>
<TH>Classic English Literature</TH>
</THEAD>
<TR>
<TD><SPAN DATAFLD="CATNAME"></SPAN></TD>
</TR>
<TR>
<TD>
<TABLE DATASRC="#dsoInventory" DATAFLD="BOOK"
BORDER=0 CELLSPACING=10>
<THEAD>
<TH>Title</TH>
<TH>Author</TH>
<TH>Binding</TH>
<TH>Pages</TH>
<TH>Price</TH>
</THEAD>
<TR ALIGN="CENTER">
<TD><SPAN DATAFLD="TITLE"
STYLE="font-style:italic"></SPAN></TD>
<TD><SPAN DATAFLD="AUTHOR"></SPAN></TD>
<TD><SPAN DATAFLD="BINDING"></SPAN></TD>
<TD><SPAN DATAFLD="PAGES"></SPAN></TD>
<TD><SPAN DATAFLD="PRICE"></SPAN></TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
Binding HTML Elements to attributes
Attributes add a bit of complexity to data binding.
When using attributes, an attribute is actually treated as if it was
a child element.
<BOOK InStock=”yes”>
<TITLE>Piers Plowman</TITLE>
<AUTHOR>William Langland</AUTHOR>
<BINDING>trade paperback</BINDING>
<PAGES>385</PAGES>
<PRICE>$10.95</PRICE></BOOK
is treated as
<BOOK>
<InStock>yes</instoc><TITLE>Piers Plowman</TITLE><AUTHOR>William
Langland</AUTHOR>
<BINDING>trade paperback</BINDING>
<PAGES>385</PAGES>
<PRICE>$10.95</PRICE>
</BOOK>
However if you had an attribute in one
of the field elements
<BOOK>
<TITLE>Piers Plowman</TITLE>
<AUTHOR>William Langland</AUTHOR>
<BINDING>trade paperback</BINDING>
<PAGES>385</PAGES>
<PRICE type=”retail”>$10.95</PRICE>
</BOOK>
In data binding the element would be interpreted like
<PRICE>
<TYPE>retail</TYPE>
$10.95</PRICE>
the DSO uses the special names $TEXT to refer to all of the character
data within an element, not including the attribute values
so it would interpret it as
<PRICE>
<TYPE>retail</TYPE>
<$TEXT>$10.95</$TEXT>
</PRICE>
So this is what we have
<!-- File Name: Inventory Attribute.htm -->
<HTML>
<HEAD>
<TITLE>Book Inventory</TITLE>
</HEAD>
<BODY>
<XML ID="dsoInventory" SRC="Inventory Valid.xml"></XML>
<H2>Book Inventory</H2>
<TABLE DATASRC="#dsoInventory" BORDER="1" CELLPADDING="5">
<THEAD>
<TH>Title</TH>
<TH>Author</TH>
<TH>Binding</TH>
<TH>Pages</TH>
<TH>Price</TH>
<TH>In Stock?</TH>
</THEAD>
<TR ALIGN="center">
<TD>
<TABLE DATASRC="#dsoInventory" DATAFLD="TITLE">
<TR>
<TD><SPAN DATAFLD="$TEXT"></SPAN></TD>
</TR>
</TABLE>
</TD
<TD>
<TABLE DATASRC="#dsoInventory" DATAFLD="AUTHOR">
<TR>
<TD><SPAN DATAFLD="$TEXT"></SPAN></TD>
<TD><SPAN DATAFLD="Born"></SPAN></TD>
</TR>
</TABLE>
</TD>
<TD><SPAN DATAFLD="BINDING"></SPAN></TD>
<TD><SPAN DATAFLD="PAGES"></SPAN></TD>
<TD><SPAN DATAFLD="PRICE"></SPAN></TD>
<TD><SPAN DATAFLD="InStock"></SPAN></TD>
</TR>
</TABLE>
</BODY>
</HTML>
Using Scripts with DSO
<!-- File Name: Inventory Find.htm -->
<HTML>
<HEAD><TITLE>Book Finder</TITLE>
</HEAD>
<BODY>
<XML ID="dsoInventory" SRC="Inventory Big.xml"></XML>
<H2>Find a Book</H2>
Title text: <INPUT TYPE="TEXT" ID="SearchText"> 
<BUTTON ONCLICK='FindBooks()'>Search</BUTTON>
<HR>
Results:<P>
<DIV ID=ResultDiv></DIV>
<SCRIPT LANGUAGE="JavaScript">
function FindBooks ()
{
SearchString = SearchText.value.toUpperCase();
if (SearchString == "")
{
ResultDiv.innerHTML = "<You must enter text into "
+ "'Title text' box.>";
return;
}
dsoInventory.recordset.moveFirst();
ResultHTML = "";
while (!dsoInventory.recordset.EOF)
{
TitleString = dsoInventory.recordset("TITLE").value;
if (TitleString.toUpperCase().indexOf(SearchString)
>=0)
ResultHTML += "<I>"
+ dsoInventory.recordset("TITLE")
+ "</I>, "
+ "<B>"
+ dsoInventory.recordset("AUTHOR")
+ "</B>, "
+ dsoInventory.recordset("BINDING")
+ ", "
+ dsoInventory.recordset("PAGES")
+ " pages, "
+ dsoInventory.recordset("PRICE")
+ "<P>";
dsoInventory.recordset.moveNext();
}
f (ResultHTML == "")
ResultDiv.innerHTML = "<no books found>";
else
ResultDiv.innerHTML = ResultHTML;
}
</SCRIPT>
</BODY>
</HTML>
|