Microsoft XML 2.5 SDK


 

XML Data Islands

[This is preliminary documentation and subject to change.]

There is an increasing need to be able to embed "islands" of data inside HTML pages. In Microsoft® Internet Explorer 5, these "data islands" can be written in Extensible Markup Language (XML).

This article describes the syntax used for embedding these data islands within a page, and details the object model exposed by the browser to enable them to be used. This method of embedding XML in HTML follows the note published by the W3C as the XML in HTML Meeting Report. The W3C expects to evolve the HTML specification to include the capability of embedding XML in HTML documents.

Embedding an XML Data Island into an HTML Page

An XML data island can be embedded using one of two methods:

Using the XML Element Within the HTML Document

This syntax is valid for Internet Explorer 5.

There are two syntactically correct ways of using the XML element within the HTML document:

<XML ID="XMLID">
  <XMLDATA>
    <DATA>TEXT</DATA>
  </XMLDATA>
</XML>
<XML SRC="http://localhost/xmlFile.xml"></XML>

The XML element is present in the HTML Document Object Model. It is in the DHTML all collection and is seen by the browser as just a regular node. The XML data within the XML element can then be accessed by calling the DHTML XMLDocument property on the XML element.

The XMLDocument property returns the root node of the XML within the XML element or the root node of the XML referenced by the value of the SRC attribute. From this root, the XML data island can be navigated using the XML document object model. The following function returns the data from the data island with the ID of "XMLID".

function returnXMLData(){
  return document.all("XMLID").XMLDocument.nodeValue;
  }

The XML element can also be referenced by ID alone. For example, the following function has the identical functionality as the previous example.

function returnXMLData(){
  return XMLID.documentElement.text;
  }

Note that because the XMLDocument property was not used, the documentElement property will need to be called to retrieve the root element of the XML.

Overloading the HTML SCRIPT Element

This syntax has been deprecated and is intended only for down-level cases.

There are three syntactically correct ways of overloading the DHTML SCRIPT element:

<SCRIPT LANGUAGE="XML">
<SCRIPT TYPE="text/xml">
<SCRIPT LANGUAGE="XML" SRC="http://localhost/xmlFile.xml"></SCRIPT>

The following HTML fragment illustrates how to embed data by overloading the SCRIPT element.

<SCRIPT ID="XMLID" LANGUAGE="XML">
  <XMLDATA>
    <DATA>TEXT</DATA>
  </XMLDATA>
</SCRIPT>

The SCRIPT element is present in the HTML page's object model (it is in theDHTML all collection and is seen by the browser as a regular script node). The XML data within the SCRIPT elements can be accessed by calling the XMLDocument property on the SCRIPT object.

The following script accesses the XML data island in the above HTML fragment and returns the name of the root node of the XML data island.

function returnIslandRootName(){
  var islandRoot = document.all.("SCRIPT").XMLDocument;
  return islandRoot.nodeName;
  }

Note that a tag that uses the name "XML" cannot be nested within an XML data island.