HTML and CSS Reference
In-Depth Information
Using JavaScript to Search an XML Document
and Display Results on a Web Page
A common use for an XML data island is providing a mechanism for users to search for
specific data items. The third hyperlink on the Calumet Restaurant Supply home page,
Search, is a link to a Web page that allows users to search for items using any part of the
description (Figure 12-36). By creating data islands that bind with a Web page, a user can
view records without conflicting with other database processes. This Web page allows
users to enter a description or part of a description, and then press the enter key or click
the Search button. If the input text field is not blank, a JavaScript function searches the
data island for matches. If matches are found, the Web page displays all the items with
descriptions matching the entered term.
The Search Items Web page (found in the Data Files for Students) is bound to
the XML document, chapter12-1products_solution.xml, and uses a JavaScript function
to search the XML recordsets for a match. The JavaScript code uses data source object
properties and methods that are built-in functions of the Internet Explorer browser.
Because the search is sequential, the order of the XML is immaterial; however, as with the
Table Web page, the XML file cannot have the XSD or XSL files bound to it.
Search button
output area
displays search
results or error
message
item-description
text field box with
partial description
entered
Figure 12-36
To Open an HTML Document and Save It with a New Name
The following steps open the HTML Web page that allows users to search an XML
document and view the results, and save the document with a new name.
1
If necessary, click the Notepad++ button on the taskbar to activate the Notepad++
window.
2
With the USB drive plugged into your computer, open chapter12-1search-items.html,
from the Chapter12\ChapterFiles folder.
3
Save the file as chapter12-1search-items_solution.html .
 
Search WWH ::




Custom Search