Because of time constraints, I decided to limit the scope to the following features of data islands, which cover about 95 percent of the current uses:
- · Binding non-tabular HTML INPUT tags to XML nodes
- · Binding non-tabular HTML DIV tags to XML nodes
- · Binding non-tabular HTML SPAN tags to XML nodes
- · Binding HTML TABLE tags to XML data islands
- · Binding tabular HTML INPUT tags to XML nodes
- · Binding tabular HTML DIV tags to XML nodes
- · Binding tabular HTML SPAN tags to XML nodes
Even though Mozilla does not provide a specific way to handle XML, it does provide a way to address parts of an HTML document and thus to access the data island: via the DOM. For example, coding document.getElementsByTagName('xml') results in a collection consisting of all XML nodes and descendents. Node attributes, like id, can be retrieved as with document.getElementsByTagName('xml').item(0).getAttribute('id'). This method can also be used to access the bound HTML nodes. This ability to access nodes and attributes is key in finding both the data islands and the associated HTML nodes.
The object shown in Listing C provides a way to access bound nodes and to differentiate between tabular and non-tabular nodes. For example, non-tabular entries for HTML DIV tags will have both a datasrc and a datafld, while tabular entries for HTML DIV tags have an entry only for datafld. In the case of the latter, the table specifies the datasrc. The node is used to ensure that the correct node is being processed, and the nodeName is used to distinguish the various types of nodes.
Processing an XML data island in Mozilla starts with finding the individual XML tags and storing them in a collection. Next, the bound table tags (those with a datasrc attribute) and their bound child nodes are processed. Finally, the stand-alone bound INPUT, DIV, and SPAN tags are handled.
Care and feeding of Mozilla XML data Islands
To invoke the MozillaDSO() function, you just need to add an onload event handler to the page's body tag, as shown in the complete example, Listing E (also in the downloadable code snippet). Once this has been accomplished, it really doesn't matter whether the client's browser is Internet Explorer or Mozilla. There is, however, one limitation to Mozilla data islands: Tags cannot close themselves. So, although <color></color> works, <color /> won't. Mozilla will insert a closing tag, usually where it will cause the most harm. In addition, you should ensure that the individual HTML node's onchange event handlers aren't overlaid with your own.