Using XML to implement BBS

Source: Internet
Author: User
Tags format implement query version xsl xsl file client

Table A:

1-0-1,this is a test
3-1-1,this is a test
4-3-1,this is a test
5-3-1,this is a test
2-0-2,this is a test
The above is an example of a list of BBS topics. In general, if you are not using Oracle (Oracle has a query that automatically generates a family tree, consult the Select ... start with ...) Connect by ... Statement, it is a cumbersome task to implement the list of examples (which many programmers have written).

What happens if we use XML instead?

Now we use "Select * from BBS" to query the post from the database and return it in XML format (if you use ADO, you can use it ... adpersistxml directly generated, of course, if you don't like the format generated by ADO, Available program generation, as in this case):

Table B:
<?xml version= "1.0"?>
<?xml-stylesheet type= "text/xsl" href= "b.xsl"?>
<post sid= "4" pid= "3" aid= "1" >
<title>4-3-1,this is a test</title>
<post sid= "5" pid= "3" aid= "1" >
<title>5-3-1,this is a test</title>
<post sid= "3" pid= "1" aid= "1" >
<title>3-1-1,this is a test</title>
<post sid= "1" pid= "0" aid= "1" >
<title>1-0-1,this is a test</title>
<post sid= "2" pid= "0" aid= "2" >
<title>2-0-2,this is a test</title>

Description: Here SID is the ID number of the post, PID is the parent ID number of the posts. Title is titled, Content is the contents of the post.
The second row in the table above specifies the use of B. XSL to transform the XML content. This is the information provided to IE5. If you use XMLDOM, then you may not want this message.
Let's take a look at how the XML content of the table above is displayed as an XSL file in the form of table A:

Table c:b.xsl
<?xml version= ' 1.0 '?>
<xsl:stylesheet xmlns:xsl= "Http://" >
<xsl:template match= "/" >
<xsl:apply-templates select= "*"/>

<xsl:template match= "POST" >
<xsl:attribute name= "title" ><xsl:value-of select= "content"/></xsl:attribute>
<xsl:value-of select= "title"/>
<xsl:if test= "/bbs/post[@pid =context ()/@sid]" >
<xsl:element name= "ul" >
<xsl:apply-templates select= "/bbs/post[@pid =context ()/@sid]"/>

<xsl:template match= "BBS" >
<xsl:apply-templates select= "post[@pid =0]"/>

Now you save Table B as Abc.xml, save the contents of Table C as b.xsl, and then open it in IE5, and you can see the same things as table A.

As you can see, the XSL file is the final result of the display. If you have more than one forum, you do not need to change the forum program, as long as the various sub forums to provide different XSL files, you can make the version of each sub-forum regardless of style or theme arrangement will have a unique performance. If free forum services are available, it is a good choice to allow forum applicants to customize their own XSL files.
But what if the client doesn't support XML? The answer is simple, the server will first convert XML into HTML, and then upload to the client.

Here we implement this example with Iis4/5+ie5+asp (server must install IE5):

<%@ LANGUAGE = JScript%>
Set rsxml=server.createobject ("ADODB. RecordSet ");
sconn = "You write Yourself"
Rsxml.cursorlocation = adUseClient sSQL, sconn, adOpenStatic

Specify the location of the XSL file
var stylefile = Server.MapPath ("simple.xsl");

Save the XML to XMLDOM
var Source = Server.CreateObject ("Microsoft.XMLDOM");
' source, adPersistXML
' I rather dislike ADO directly save XML documents, I always do:

Dim getdata,v
GetData = GetData & "<bbs>"
While not rs_foruminfo.eof
GetData = GetData & "<post>"
For i = 0 to Rs_foruminfo.fields.count-1
Set v = RS_ForumInfo.Fields.Item (i)
if (v.type=201) or (v.type=203) or (v.type=205) then
GetData = getdata& "<" & RS_ForumInfo.Fields.Item (i). Name & ">" &_
"<! [Cdata[& RS_ForumInfo.Fields.Item (i). Value & "]]>" &_
"</" & RS_ForumInfo.Fields.Item (i). Name & ">"
GetData = getdata& "<" & RS_ForumInfo.Fields.Item (i). Name & ">" &_
RS_ForumInfo.Fields.Item (i). Value &_
"</" & RS_ForumInfo.Fields.Item (i). Name & ">"
End If
Set V = Nothing
GetData = GetData & "</post>"

GetData = GetData & "</bbs>"

Source.loadxml GetData

Load the XSL
var style = Server.CreateObject ("Microsoft.XMLDOM");
Style.async = false;
Style.load (Stylefile);

Response.Write (Source.transformnode (style));

Of course, because it is easy to use ADO directly to generate XML, simple.xsl is different from the b.xsl above.
The reader can refer to the above example and XSL reference (the 2000 MSDN has a more detailed xml/xsl SDK documentation) to write.

Related Article

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.