I found this article in code project. May be most of you know about it, but I came to know recently. Its an easy way to load an xml in html without much of hassle.
DSO is an object that operates like a database on the client side. It will accept information that is organized in a certain way and will manipulate it with its own database engine. Like any object it has an interface with its own properties and methods, and you can manipulate the data stored in the object using these methods. The default behavior of XML DSO is to validate the document and to resolve external entities as the XML document is loaded.
Loading external files
The simple HTML code creates an XML DSO with a DOM object and loads it with the file equip.xml. At the same time this file is loaded, equip.xml is validated and all the external entities are expanded. The
async="false" attribute is added to make sure all the XML data is loaded before any other HTML processing takes place.
XML File Format
DSO allows data binding to HTML table elements. When a table element is bound there is no need to write out the code for individual rows for each record in the recordset. The DSO will automatically do this for each record.
To bind the XML data to an HTML table, add a
datasrc attribute to the table element, and add the
datafld attribute to the
span elements inside the table data.
Here name, rate and manufacturer are used to bind the data to the HTML element. We can bind to the input textboxes and all other elements in the same way:
First we create a new DSO via code:
Next we make a DOM object. This is done using the
XMLDocument property of the DSO.
Once a DOM object has been created use the
load method of the DOM object to load a file:
//Following function is used to load the "equip.xml" file..
"Equipment Details ";
//Following function is used to load the "details.xml" file..
"Staff Details ";
The complete source code is given below: