


Detailed introduction to using XML to implement BBS (topic list)
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 BBS topic list. Generally speaking, if you are not using Oracle (Oracle has a query statement that can automatically generate a family tree, please refer to the Select... startwith... connect by... statement), then how to implement the list in the above example is troublesome. Work (I believe many programmers have written this).
If we use xml instead, what will be the result?
Now we use "Select * from bbs" to query posts from the database and return them in XML format (if you are using ADO, you can use its RecordSet.Save... adPersistXML to generate it directly. Of course, if you don't like it, The format generated by ADO can be generated by a program, such as this example):
Table B:
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="b.xsl"?> <bbs> <post sid="4" pid="3" aid="1"> <title>4-3-1,this is a test</title> <content>slddfjslajfsdljf</content> </post> <post sid="5" pid="3" aid="1"> <title>5-3-1,this is a test</title> <content>slddfjslajfsdljf</content> </post> <post sid="3" pid="1" aid="1"> <title>3-1-1,this is a test</title> <content>slddfjslajfsdljf</content> </post> <post sid="1" pid="0" aid="1"> <title>1-0-1,this is a test</title> <content>slddfjslajfsdljf</content> </post> <post sid="2" pid="0" aid="2"> <title>2-0-2,this is a test</title> <content>slddfjslajfsdljf</content> </post> </bbs>
Description: Here sid is the id number of the post, and pid is the parent id number of the post. title is the title and content is the content of the post.
The second row in the above table specifies the use of b.XSL to convert XML content. This is the information provided to IE5. If you use XMLDOM, you don't need this message.
Let’s take a look at how to display the XML content of the above table into an XSL file in the form of Table A:
Table C: b.XSL
<?xml version=''1.0''?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <html> <body> <xsl:apply-templates select="*"/> </body> </html> </xsl:template> <xsl:template match="post"> <li> <div> <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:element> </xsl:if> </div> </li> </xsl:template> <xsl:template match="bbs"> <ul> <xsl:apply-templates select="post[@pid=0]"/> </ul> </xsl:template> </xsl:stylesheet>
Now, you will table Save the content of B as abc.xml, save the content of table C as b.xsl, and then open it in IE5, you can see the same content as table A.
It can be seen that the XSL file determines the final display result. If you have multiple sub-forums, there is no need to change the forum program. As long as you provide different XSL files for each sub-forum, you can make each sub-forum have a unique performance regardless of the style, screen or theme arrangement. If free forum services are provided, it would be a good choice to allow forum applicants to customize their own XSL files.
But what should we do if the client does not support XML? The answer is simple. The server first converts XML into HTML and then transmits it to the client.
Below we use IIS4/5+IE5+asp to implement this example (the server must have IE5 installed):
<%@ LANGUAGE = JScript %> <% Set rsXML=Server.CreateObject("ADODB.RecordSet"); sSQL = “SELECT * from bbs" sConn = “你自个儿写” rsXML.CursorLocation = adUseClient rsXML.Open sSQL, sConn, adOpenStatic //指定XSL文件位置 var styleFile = Server.MapPath("simple.xsl"); // Save the XML to XMLDOM var source = Server.CreateObject("Microsoft.XMLDOM"); ''rsXML.Save source, adPersistXML ''我相当不喜欢ADO直接Save出来的XML文档,我总是这样做: 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 &">" else 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 next GetData = GetData & "</post>" RS_ForumInfo.MoveNext wend 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, for the sake of simplicity, ADO is used directly to generate XML, so simple.xsl is different from b.xsl above.
Readers can refer to the above example and XSL reference materials (MSDN in 2000 has a more detailed XML/XSL SDK document) to write. (End)
The above is the detailed introduction of using XML to implement BBS (topic list). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Can XML files be opened with PPT? XML, Extensible Markup Language (Extensible Markup Language), is a universal markup language that is widely used in data exchange and data storage. Compared with HTML, XML is more flexible and can define its own tags and data structures, making the storage and exchange of data more convenient and unified. PPT, or PowerPoint, is a software developed by Microsoft for creating presentations. It provides a comprehensive way of

Using Python to merge and deduplicate XML data XML (eXtensibleMarkupLanguage) is a markup language used to store and transmit data. When processing XML data, sometimes we need to merge multiple XML files into one, or remove duplicate data. This article will introduce how to use Python to implement XML data merging and deduplication, and give corresponding code examples. 1. XML data merging When we have multiple XML files, we need to merge them

Implementing filtering and sorting of XML data using Python Introduction: XML is a commonly used data exchange format that stores data in the form of tags and attributes. When processing XML data, we often need to filter and sort the data. Python provides many useful tools and libraries to process XML data. This article will introduce how to use Python to filter and sort XML data. Reading the XML file Before we begin, we need to read the XML file. Python has many XML processing libraries,

Convert XML data in Python to CSV format XML (ExtensibleMarkupLanguage) is an extensible markup language commonly used for data storage and transmission. CSV (CommaSeparatedValues) is a comma-delimited text file format commonly used for data import and export. When processing data, sometimes it is necessary to convert XML data to CSV format for easy analysis and processing. Python is a powerful

Importing XML data into the database using PHP Introduction: During development, we often need to import external data into the database for further processing and analysis. As a commonly used data exchange format, XML is often used to store and transmit structured data. This article will introduce how to use PHP to import XML data into a database. Step 1: Parse the XML file First, we need to parse the XML file and extract the required data. PHP provides several ways to parse XML, the most commonly used of which is using Simple

Python implements conversion between XML and JSON Introduction: In the daily development process, we often need to convert data between different formats. XML and JSON are common data exchange formats. In Python, we can use various libraries to convert between XML and JSON. This article will introduce several commonly used methods, with code examples. 1. To convert XML to JSON in Python, we can use the xml.etree.ElementTree module

Handling Errors and Exceptions in XML Using Python XML is a commonly used data format used to store and represent structured data. When we use Python to process XML, sometimes we may encounter some errors and exceptions. In this article, I will introduce how to use Python to handle errors and exceptions in XML, and provide some sample code for reference. Use try-except statement to catch XML parsing errors When we use Python to parse XML, sometimes we may encounter some

The full name of bbs is Bulletin Board System, which means "electronic bulletin board system" in Chinese. It generally refers to an online forum and is an online communication place related to network technology. Its characteristics: large amount of information, fast information update, and strong interactivity.
