Works in: Internet Explorer 5.x
Have you started adding XML-based documents to your Web sites? If you have not, then let me be the one to tell you that it is high time you learn how to do so. XML technology has quickly become the standard for defining data on The Net.
In this month's 10-Minute Solution, I will give you a very easy to understand introduction to XML. In the months to follow, I will present XML-based solutions of progressively higher levels of complexity, power and usefulness.
To start with, let me say that you should not be intimidated by XML in any way. If you know HTML, you will quickly understand how to create XML documents since both markup "languages" are based on the idea that you will surround text with tags, <my_tag>like this</my_tag>.
Let's start by introducing the <XML> tag. It looks harmless enough.
<XML ID=xmlEmployees SRC="Employees.xml">
</XML>
The keyword "XML" is used to identify this as an <XML> tag (not too difficult so far). A couple of attributes are part of the tag.
The attribute, "ID" is used to give a name to this <XML> tag. Whenever we want to reference the <XML> tag in any way, we will use the value of the "ID" attribute.
The "SRC" attribute identifies the file that contains the actual data. You have the option of putting the actual data inside of the <XML> tag (shown above) or putting the actual data in an external file. Putting the data in an external file is usually a bit more flexible since that approach separates the data (in the external .XML file) from the display of the data (the .HTML file). If you choose to put the data in an external .XML file, the "SRC" attribute is required, otherwise it can be omitted.
One of the ways you can use the XML data in your HTML page is to display that data in a standard HTML table. To do so, you should tell that table which set of XML data should be displayed. The DATASRC attribute of the <TABLE> tag provides that information quite nicely. The following example shows how.
<TABLE DATASRC=#xmlEmployees>
</TABLE>
In addition, you must also tell the table which XML data field should be shown in which table columns. The DATAFLD attribute of the <DIV> tag can handle it. A <DIV> tag, such as the one shown below will automatically display the appropriate data. If the above <DIV> tag is place within a <TABLE> that has a DATASRC attribute properly specified, the <DIV> will populate with data from the XML.