Other ways to include XML data in your data access page are to embed the XML data and tags inside the page or to refer to an external XML file from within the page. This is done through the use of "data islands" inserted inside the page. Data islands are created by inserting XML data between <XML> tags within the page. The information inside the tags is formatted in XML syntax.
Embedding XML data
In this technique, the actual XML data and tags are embedded in the body of the page between <XML> tags. To include the XML data and tags into a data island, you set the XMLLocation property of the page to dscXMLEmbedded and the UseXMLData property to True, and then call the ExportXML method to embed the XML. For example, if you wanted to embed the XML data once, as opposed to every time you open the page, you could call the ExportXML method from the Immediate Window (CTRL+G from within Access) in the Microsoft Visual Basic Editor and execute:
DataAccessPages(0).MSODSC.ExportXML
where:
DataAccessPages(0) refers to the current page,
and MSODSC refers to the Microsoft Office Data Source Control.
To embed the XML data every time you open the page, you could include the code in an event procedure for the page such as the OnOpen event of the page. The following is an example of XML data and tags embedded in an .htm page:
<HTML>
...
<BODY>
<p>This is a segment of a data access page</p>
<!-- The XML tag starts the data island -->
<XML ID=OrderData>
<ORDERS>
<ITEM ID=1>
<NAME>Aniseed Syrup</NAME>
<PRICE>10.95</PRICE>
</ITEM>
</ORDERS>
</XML>
</BODY>
</HTML>
Linking to external XML data
In this technique, the <XML> tag is used again in the body of the document to separate the XML data from the presentation data. However, instead of including the XML data between the tags, an SRC attribute is used to point to an external XML data file on a Web server. To bind the page to an XML file, you set the XMLLocation property of the page to dscXMLDataFile, the UseXMLData property to True, and the XMLDataTarget property to the location of the XML data file. The following is an example of an .htm file with a link to an external XML file:
<HTML>
...
<BODY>
<p>This is a portion of a data access page</p>
<!-- Again, the XML tag starts the data island
which contains a link to an external XML file -->
<XML ID=xmlData1 SRC="orders.xml"></XML>
</BODY>
</HTML>
Notice that in this case, the SRC attribute points to a static data file. The XML data island could also point to an ASP file that generates XML output data such as:
<XML ID=xmlData2 SRC="getorders.asp"></XML>
You can also dynamically change the SRC attribute of XML data islands by using script, as in the following example:
<HTML>
...
<BODY>
<SCRIPT LANGUAGE=javascript>
function getXML(id) {
xmlData1.src = "getorders.asp?userid=" + id;
}
</SCRIPT>
<p>This is a portion of a data access page</p>
<XML ID=xmlData1"></XML>
<INPUT TYPE=button VALUE=User1 ONCLICK="return
getXML(1)">
<INPUT TYPE=button VALUE=User2 ONCLICK="return
getXML(2)">
</BODY>
</HTML>
In this example, the user presses a button which determines which set of XML data is returned. If the user presses button btn_User1, the userid "1" is passed to the function getXML which, in turn, calls the getorders.asp and returns the set of data for "User 1", and so forth.
Conclusion
XML has become the preferred method of exchanging data between applications and across Web pages. By including XML data in your data access pages, you make the data in your pages available to more applications.