


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)!

如何用PHP和XML实现网站的分页和导航导言:在开发一个网站时,分页和导航功能是很常见的需求。本文将介绍如何使用PHP和XML来实现网站的分页和导航功能。我们会先讨论分页的实现,然后再介绍导航的实现。一、分页的实现准备工作在开始实现分页之前,需要准备一个XML文件,用来存储网站的内容。XML文件的结构如下:<articles><art

一、XML外部实体注入XML外部实体注入漏洞也就是我们常说的XXE漏洞。XML作为一种使用较为广泛的数据传输格式,很多应用程序都包含有处理xml数据的代码,默认情况下,许多过时的或配置不当的XML处理器都会对外部实体进行引用。如果攻击者可以上传XML文档或者在XML文档中添加恶意内容,通过易受攻击的代码、依赖项或集成,就能够攻击包含缺陷的XML处理器。XXE漏洞的出现和开发语言无关,只要是应用程序中对xml数据做了解析,而这些数据又受用户控制,那么应用程序都可能受到XXE攻击。本篇文章以java

当我们处理数据时经常会遇到将XML格式转换为JSON格式的需求。PHP有许多内置函数可以帮助我们执行这个操作。在本文中,我们将讨论将XML格式转换为JSON格式的不同方法。

Pythonxmltodict对xml的操作xmltodict是另一个简易的库,它致力于将XML变得像JSON.下面是一个简单的示例XML文件:elementsmoreelementselementaswell这是第三方包,在处理前先用pip来安装pipinstallxmltodict可以像下面这样访问里面的元素,属性及值:importxmltodictwithopen("test.xml")asfd:#将XML文件装载到dict里面doc=xmltodict.parse(f

使用nmap-converter将nmap扫描结果XML转化为XLS实战1、前言作为网络安全从业人员,有时候需要使用端口扫描利器nmap进行大批量端口扫描,但Nmap的输出结果为.nmap、.xml和.gnmap三种格式,还有夹杂很多不需要的信息,处理起来十分不方便,而将输出结果转换为Excel表格,方面处理后期输出。因此,有技术大牛分享了将nmap报告转换为XLS的Python脚本。2、nmap-converter1)项目地址:https://github.com/mrschyte/nmap-

Scrapy是一款强大的Python爬虫框架,可以帮助我们快速、灵活地获取互联网上的数据。在实际爬取过程中,我们会经常遇到HTML、XML、JSON等各种数据格式。在这篇文章中,我们将介绍如何使用Scrapy分别爬取这三种数据格式的方法。一、爬取HTML数据创建Scrapy项目首先,我们需要创建一个Scrapy项目。打开命令行,输入以下命令:scrapys

xml中node和element的区别是:Element是元素,是一个小范围的定义,是数据的组成部分之一,必须是包含完整信息的结点才是元素;而Node是节点,是相对于TREE数据结构而言的,一个结点不一定是一个元素,一个元素一定是一个结点。

1.在Python中XML文件的编码问题1.Python使用的xml.etree.ElementTree库只支持解析和生成标准的UTF-8格式的编码2.常见GBK或GB2312等中文编码的XML文件,用以在老旧系统中保证XML对中文字符的记录能力3.XML文件开头有标识头,标识头指定了程序处理XML时应该使用的编码4.要修改编码,不仅要修改文件整体的编码,还要将标识头中encoding部分的值修改2.处理PythonXML文件的思路1.读取&解码:使用二进制模式读取XML文件,将文件变为


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

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!
