SoFunction
Updated on 2025-04-08

Simple combination of XML and ASP to implement HTML template functions

This article uses the DSO data binding function of XML to achieve the separation of ASP code and HTML code, thereby realizing the function of quickly replacing HTML templates. Since I have just started to get involved in XML, I don’t know much about it. Here I am just putting forward some ideas. If there are any errors in this article, please refer to it.

At present, the quick template replacement function is basically to replace the special tags in the replacement template before displaying them, which increases the processing time of many ASPs. Moreover, if the template file is too long, it is also a test for the server memory when loading it into memory for processing. XML provides a DSO data binding function. The identity replacement operation can be delivered to the client. Since in order to simplify the production requirements of HTML templates, it is necessary to try to simplify the XML technical content of HTML templates.

Simply put, this method is just implemented using the properties of the two HTML tags datasrc and dataFLd. I won’t say much nonsense, all instances speak. The following two examples will illustrate everything.

Example 1: Single data display
The following is the XML data island generated using ASP.
<xml > 
<xData> 
<name>coder</name> 
<webname>The light and free pearl</webname>
<weburl>/oyiboy</weburl> 
</xData> 
</xml> 

The HTML original code when displaying:
<table datasrc="#xmldata" border=1> 
<tr> 
<td colspan=2>My brief introduction</td>
</tr> 
<tr> 
<td>My name:</td>
<td><span dataFLd="name"></span></td> 
</tr> 
<tr> 
<td>Website name:</td>
<td><span dataFLd="webname"></span></td> 
</tr> 
<tr> 
<td>Website Address:</td>
<td><a dataFLd="weburl"><span dataFLd="weburl"></span></a></td> 
</tr> 
</table> 


Example 2: Multiple data display
The following is the XML data island generated using ASP.
<xml > 
<xData> 
<webList> 
<webname>The light and free pearl</webname>
<weburl>/oyiboy</weburl> 
</webList> 
<webList> 
<webname>Estyle(Jin Tian)'s crazy thinking</webname>
<weburl>/estyle</weburl> 
</webList> 
<webList> 
<webname>Favorite cabbage</webname>
<weburl>/qunluo</weburl> 
</webList> 
</xData> 
</xml> 

The HTML original code when displaying:
<table datasrc="#xmldataList" border=1> 
<thead> 
<tr> 
<td colspan=2>The list of Csdn Blogs I follow</td>
</tr> 
<tr> 
<td align="center">name</td>
<td align="center">Address</td>
</tr> 
</thead> 
<tbody> 
<tr> 
<td><span dataFLd="webname"></span></td> 
<td><a dataFLd="weburl"><span dataFLd="weburl"></span></a></td> 
</tr> 
</tbody> 
</table> 

(The above two examples can be copied into a file to view the actual running effect.)
Note that the head and tbody in the HTML original code in Example 2 will be useful when displaying multiple records. If you don’t understand what they are useful, you can remove them and see what consequences will be.

By the way, the data binding of images and keys and the binding of hyperlinks are similar, such as: <img dataFLd="webimg"> and <button dataFLd="buttonvalue"></button>

The limitation is that the browser must support XML, and there is still a question. In Example 1, the <a dataFLd="weburl"><span dataFLd="weburl"></span></a> will show the effect of <a href="/oyiboy">/oyiboy</a>. If you want to achieve the effect of <a href="/oyiboy/?loginname=code">/oyiboy</a> without modifying the XML data, please give me some advice.