This section demonstrates a small XML application framework.
--------------------------------------------------------------------------------
Starting from an XML document
First, we build a simple XML document.
Take a look at our original XML document and describe the CD directory.
<?xml version= "1.0" encoding= "Iso-8859-1"?>
<CATALOG>
<CD>
<title>empire burlesque</title>
<artist>bob dylan</artist>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
.
.
... more ...
.
--------------------------------------------------------------------------------
Loading an XML document into a data island
The data island can access XML files.
With the data island, XML documents can be introduced into HTML pages.
<xml src= "Cd_catalog.xml" id= "Xmldso" async= "false" >
</xml>
Using the example code above, you can load the Cd_catalog.xml file into a data island called "Xmldso". The effect of property async= "False" is to ensure that all data in an XML document is loaded into memory before the HTML processor begins processing the XML data.
--------------------------------------------------------------------------------
Binding XML data to a TABLE element in HTML
The table element in HTML can be used to display XML data.
To enable your XML data to be displayed in an HTML page, you must bind the data island to an HTML element.
Binding XML data to a TABLE element requires adding a resource property to the Table property and adding field properties to the SPAN element:
<table datasrc= "#xmldso" width= "100%" border= "1" >
<thead>
<th>Title</th>
<th>Artist</th>
<th>Year</th>
</thead>
<tr align= "Left" >
<td><span datafld= "TITLE" ></span></td>
<td><span datafld= "ARTIST" ></span></td>
<td><span datafld= "Year" ></span></td>
</tr></table>
--------------------------------------------------------------------------------
Bind the data island to a <span> or <div> element
<span> or <div> elements can be used to display XML data.
It is not necessary to use the table element to display the XML data, which can be bound to any HTML element by the data island.
All you have to do is add some <span> or <div> elements to your page and use data resource attributes to bind each element to an XML document element, as follows:
<BR/>title:
<span datasrc= "#xmldso" datafld= "TITLE" ></span>
<BR/>artist:
<span datasrc= "#xmldso" datafld= "ARTIST" ></span>
<BR/>year:
<span datasrc= "#xmldso" datafld= "year" ></span>
Or in a form like this:
<BR/>title:
<div datasrc= "#xmldso" datafld= "TITLE" ></div>
<BR/>artist:
<div datasrc= "#xmldso" datafld= "ARTIST" ></div>
<BR/>year:
<div datasrc= "#xmldso" datafld= "year" ></div>
Note that if you use the <div> element, the data will be displayed in a new line.
In the example above, you can see that the XML data is displayed in one row. If you want to control the line of data, you must add some script in your code.
--------------------------------------------------------------------------------
Add a navigation script to your XML data
You can use a scripting program to implement navigation capabilities.
Add the data island method, using the Scripting Functions MoveNext () and MovePrevious () to implement the navigation function.
<script type= "Text/javascript" >
function MoveNext ()
{
X=xmldso.recordset
if (X.absoluteposition < X.recordcount)
{
X.movenext ()
}
}
function MovePrevious ()
{
X=xmldso.recordset
if (X.absoluteposition > 1)
{
X.moveprevious ()
}
}
</script>
--------------------------------------------------------------------------------
Summary
If you are creative, you can write a very sophisticated application.
If you use the knowledge that you have learned on this page, you can easily create a perfect application with your imagination.