XML Data Island
With Internet Explorer, the unofficial <xml> tag can be used to
create an XML data island.
XML Data Embedded in HTML
An XML data island is XML data embedded into an HTML page.
Here is how it works; assume we have the following XML document ("note.xml"):
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
|
Then, in an HTML document, you can embed the XML file above with the <xml>
tag. The id attribute of the <xml> tag defines an ID for the data island, and the src
attribute points to the XML file to embed:
<html>
<body>
<xml id="note" src="note.xml"></xml>
</body>
</html>
|
However, the embedded XML data is, up to this point, not visible for the user.
The next step is to format and display the data in the data island by
binding it to HTML elements.
Bind Data Island to HTML Elements
In the next example, we will embed an XML file called "cd_catalog.xml"
into an HTML file.
View "cd_catalog.xml".
The HTML file looks like this:
<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>
|
Example explained:
The datasrc attribute of the <table> tag binds the HTML table element to
the XML data island. The datasrc attribute refers to the id attribute of the
data island.
<td> tags cannot be bound to data, so we are using <span> tags. The
<span> tag allows the datafld attribute to refer to the XML element to
be displayed. In this case, it is datafld="ARTIST" for the <ARTIST> element
and datafld="TITLE" for the <TITLE> element in
the XML file. As the XML is read, additional rows are created for each <CD>
element.
If you are running IE 5.0 or higher, you can
try
it yourself.
Also try this example,
demonstrating <thead>, <tbody>, and <tfoot>.
|