Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XML Developer's Guide

Data Islands

In Microsoft® Internet Explorer 5.0, you can the use <XML> element to create a data island. Data islands are XML data referenced or included in an HTML page. The XML data can be included within the HTML or it can be in an external file.

Using the <XML> element allows you to avoid using script; if the user has disabled scripting for security reasons, the object tag version will not work because script is required to initialize the XML.

Inline XML

Inline XML is enclosed within the <XML> and </XML> tags, as shown in the following example.

<XML ID="xmlData">
<?xml version="1.0" ?>
<trees>
<tree>
<name>Birch</name>
<height unit="foot">10</height>
</tree>
<tree>
<name>Aspen</name>
<height unit="foot">4</height>
</tree>
</trees>
</XML>

References to XML Files

External XML uses the SRC attribute on the <XML> tag to reference an external file. The SRC attribute can refer to a local file or specify a URL. By using URLs that point to external servers, data can be integrated from several sources. The following code uses the SRC attribute with a local file.

<XML ID="xmlData" SRC="xmlData.xml"></XML>

The file xmlData.xml contains the XML. The SRC attribute can refer to a URL as well, as in the following example.

<XML ID="xmlData" SRC="http://msdn.microsoft.com/workshop/author/composer.xml">
</XML>

Reading Data from Within a Data Island

The ID attribute of the <XML> element is used to reference the data island. By using HTML tags that can accept data source tags (binding the HTML to the data), you can format and display the data in the XML data island. The following example displays the XML items tagged with <meeting>.

<HTML><HEAD></HEAD><TITLE></TITLE>
<BODY>
<XML ID="xmlMeetings">
<?xml version="1.0" ?>
<meetings>
<meeting>
<date>1/1/99</date>
<time>9:00</time>
<location>104</location>
</meeting>
<meeting>
<date>2/1/99</date>
<time>13:00</time>
<location>34</location>
</meeting>
<meeting>
<date>3/1/99</date>
<time>14:30</time>
<location>20</location>
</meeting>
</meetings>
</XML>
<table datasrc="#xmlMeetings">
<tr>
<td><div datafld="date"></div></td>
<td><div datafld="time"></div></td>
<td><div datafld="location"></div></td>
</tr>
</table>
</BODY>
</HTML>

The <table> element uses the datasrc attribute to reference the inline XML. The datasrc refers to the ID attribute used to identify the XML, preceded by a pound sign (#). The TD element cannot be bound to data, so a tag that binds to data must be used. In this case, it is the <DIV> element. The <DIV> element also allows the datafld attribute to refer to the XML element to place in this cell of the table. In this case, it is datafld="date" for the <date> XML element.

As the XML is read, additional rows are created for each element tagged with the <meeting> tag.