操作系统  办公  实用知识  设计  开发  WEB开发  移动开发  数据库  软件工程  网管  安全  管理  信息化  答疑  渠道 

用Flash和XML构建论坛实例(上)

2004-5-15 作者:翅膀 网友评论 0 条 点击进入论坛

  前面一篇《》介绍了在Flash中使用XML来实现通讯的原理。现在我们就来看看这方面的应用实例――用Flash、Asp、XML来构建一个论坛。
  先来看看论坛的功能,有登陆,查看主题,查看正文,发表新主题,回复主题,删除,权限管理等等基本功能,根据需要在此基础上稍作修改,就可以实现一个功能比较完备的论坛了。下面就按顺序一个一个来实现论坛的功能,每一个介绍的内容都分为“传递的XML”、“Flash端”、“Asp端”三部分。  

  一、登陆

  登陆就是将用户名和密码用XML格式发送到服务器端,服务器端将验证的结果用XML格式返回。

  A、传递的XML


  所谓传送的XML,就是在服务器端跟Flash端之间传送的XML字符串,也就是一般意义上的通讯报文了。

  1、请求报文

 


用户名密码

  2、响应报文

 


  B、Flash端

  1、在Flash MX 2004中新建一个Flash文件,在场景的第一帧的ActionScript面板上增加语句:

  stop();

  2、在第一帧的场景中用文本工具拉两个文本框,类型都为“Input type”,变量名var分别设置为“username”、“pwd”,这是用来输入用户名跟密码的。

  3、新建一个Button并拖到第一帧的场景中,摆放位置如图1所示。并在这个Button的ActionScript面板中增加如下语句:

 


on(release){
loginXml = new XML(); // 注释1
loginElement = loginXml.createElement("LOGIN"); // 注释2
// name node
nameElement = loginXml.createElement("USERNAME"); // 注释3
nameNode = loginXml.createTextNode("name"); // 注释4
nameNode.nodeValue = _root.username; // 注释5
nameElement.appendChild(nameNode); // 注释6
// pwd node
pwdElement = loginXml.createElement("PWD"); // 注释7
pwdNode = loginXml.createTextNode("pwd");
pwdNode.nodeValue = _root.pwd;
pwdElement.appendChild(pwdNode);
loginElement.appendChild(nameElement); // 注释8
loginElement.appendChild(pwdElement); // 注释9
loginXml.appendChild(loginElement); // 注释10

xmlRepley = new XML(); // 注释11
xmlRepley.onLoad = onLoginReply; // 注释12
function onLoginReply (success) {
if (success) { // 注释13
if (xmlRepley.firstChild.firstChild.attributes.right == "1") { // 注释14
_root.gotoAndPlay("main")
}else {
_root.username = "登陆失败";
}
}
}
loginXml.sendAndLoad("http://localhost/xmlbbs/login.asp", xmlRepley); // 注释15
}

  注释1:新建一个XML对象,这是用来发送到服务器端的。

  注释2:创建一个LOGIN结点对象。

  注释3:创建一个USERNAME结点对象,注意不能直接在Element对象中放置文本内容,要在Text Node对象中才能放置文本内容。具体可以参见Flash帮助文件中有关XML.createElement()和XML.createTextNode() 中的内容。

  注释4:创建一个Text Node对象,用来放置USERNAME结点的文本内容。

  注释5:对Text Node结点赋值。

  注释6:将创建的Text Node结点插入到USERNAME结点对象中。

  注释7:分别创建一个PWD结点对象和Text Node,并将Text Node结点插入到PWD结点对象中。

  注释8:将USERNAME结点对象插入到LOGIN结点对象中。

  注释9:将PWD结点对象插入到LOGIN结点对象中。

  注释10:将LOGIN结点对象插入到所创建的XML对象中,从而构造一个完整的XML对象。注意这里在构建XML对象时,是从最里面开始构建的。

  注释11:新建一个XML对象,这里是用来放置接收到的XML对象的。

  注释12:设置接收XML对象的响应函数,当服务器端返回XML对象的时候触发。

  注释13:success是标示XML对象是否从服务器返回的标示位。

  注释14:判断返回的XML对象中的结点属性是否符合要求。

  注释15:利用sendAndLoad()函数,将Flash端的XML对象发送到服务器端,并接收从服务器端返回的XML对象。


 

[下一页]


 

  C、Asp端

  新建一个Asp文件,命名为login.asp,输入如下的内容:


<%
Set MyFileObject = Server.CreateObject("Scripting.FileSystemObject") ‘注释1
Set MyTextFile = MyFileObject.CreateTextFile("G:\写作\flashxmlbbs\login.xml", 8, TRUE) ‘注释2
MyTextFile.WriteLine(Request.Form) ‘注释3

set objDom = server.CreateObject("microsoft.xmldom") ‘注释4
objDom.loadxml(Request.Form) ‘注释5
set objname = objdom.documentElement.SelectSingleNode("//LOGIN/USERNAME") ‘注释6
username = objname.text ‘注释7

set objpwd = objdom.documentElement.SelectSingleNode("//LOGIN/PWD") ‘注释8
pwd = objpwd.text
righ = "-1"

''判断
set conn=Server.CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/xmlbbs/xmlbbs.mdb") ‘注释9
set rs=Server.CreateObject("ADODB.Recordset") ‘注释10
strSql="select * from UserInfo where username = ''" & username & "'' and userpwd = ''" & pwd & "''" ‘注释11
rs.open strSql,conn, 1, 1 ‘注释12
if not(rs.bof and rs.eof) then ‘注释13
righ = rs("userright") ‘注释14
Else
righ = "0"
end if
rs.close
conn.close

''返回
response.write("<LOGIN><USRENAME name=""" & username & """ right=""" & righ & """>" & username & "</USERNAME></LOGIN>") ‘注释15
%>

  注释1:利用FileSystemObject组件建立一个文件对象,将通讯过程中传送的东西写在文件里面,方便调试。

  注释2:根据实际需要修改文件的路径。

  注释3:把Request.Form是传送进来的所有内容都写在文件里面,在服务器端留下痕迹。

  注释4:创建一个XML对象。可以在MS XML包中找到更多有关XML操作的信息。

  注释5:通过loadxml()函数,导入Flash端传送进来的XML格式字符串。

  注释6:建立USERNAME结点的对象。

  注释7:取得USERNAME结点的内容。

  注释8:建立PWD结点的对象,取得PWD结点的内容。

  注释9:建立一个数据库的ADO连接,这里用到的是Access 2000数据库,数据库的格式见后面的附录,请注意数据库的存放位置。

  注释10:建立一个数据库Recordset集合。

  注释11:根据取得的用户名和密码,构造一个SQL字符串。

  注释12:根据构造的SQL字符串去查询数据库。

  注释13:判断用户名及密码是否正确。

  注释14:用户名及密码正确,取得数据库中相应的权限。

  注释15:直接构造一个XML字符串,并通过write函数写到Flash端。

  二、查看主题

  查看主题就是Flash端向服务器端发送请求,服务器端将数据库中所保存的文章主题用XML格式发送到Flash端。

  A、传递的XML

  1、请求报文


<TITLE>< /TITLE >

   2、响应报文


<TITLE title1=”标题1” id1=”编号1” title2=”标题2” id2=”编号2” title3=”标题3” id3=”编号3” title4=”标题4” id4=”编号4” title5=”标题5” id5=”编号5” title6=”标题6” id6=”编号6” title7=”标题7” id7=”编号7” title8=”标题8” id8=”编号8” title9=”标题9” id9=”编号9” title10=”标题10” id10=”编号10”>< /TITLE >

  B、Flash端

  1、在场景的第二帧上“插入关键帧”,将此帧命名为“main”,并在此帧的Action Script面板上增加如下语句:

fileNowId = "0";
fileId1 = "0";
fileId2 = "0";
fileId3 = "0";
fileId4 = "0";
fileId5 = "0";
fileId6 = "0";
fileId7 = "0";
fileId8 = "0";
fileId9 = "0";
fileId10 = "0";
stop();

  注释:上面这些变量都是为了保存从服务器端返回的Id号而设置的。

  2、在第二帧的场景中用文本框工具拉十个文本框,类型都设置为“Input Type”,变量var分别设置为“title1”、“title2”、“title3”、“title4”、“title5”、“title6”、“title7”、“title8”、“title9”、“title10”。

  3、在第二帧的场景中增加一个显示为“更新”Button,用来更新主题,在此Button的Action Script面板上增加如下语句:


on(release){
titleXml = new XML(); // 注释1
titleElement = titleXml.createElement("TITLE"); // 注释2
loginElement.appendChild(titleElement); // 注释3
titleXml.appendChild(titleElement);

titleRepley = new XML(); // 注释4
titleRepley.onLoad = onTitleReply; // 注释5
function onTitleReply (titlesuccess) {
if (titlesuccess) { // 注释6
_root.title1 = titleRepley.firstChild.attributes.title1; // 注释7
_root.title2 = titleRepley.firstChild.attributes.title2;
_root.title3 = titleRepley.firstChild.attributes.title3;
_root.title4 = titleRepley.firstChild.attributes.title4;
_root.title5 = titleRepley.firstChild.attributes.title5;
_root.title6 = titleRepley.firstChild.attributes.title6;
_root.title7 = titleRepley.firstChild.attributes.title7;
_root.title8 = titleRepley.firstChild.attributes.title8;
_root.title9 = titleRepley.firstChild.attributes.title9;
_root.title10 = titleRepley.firstChild.attributes.title10;
_root.fileId1 = titleRepley.firstChild.attributes.id1; //注释8
_root.fileId2 = titleRepley.firstChild.attributes.id2;
_root.fileId3 = titleRepley.firstChild.attributes.id3;
_root.fileId4 = titleRepley.firstChild.attributes.id4;
_root.fileId5 = titleRepley.firstChild.attributes.id5;
_root.fileId6 = titleRepley.firstChild.attributes.id6;
_root.fileId7 = titleRepley.firstChild.attributes.id7;
_root.fileId8 = titleRepley.firstChild.attributes.id8;
_root.fileId9 = titleRepley.firstChild.attributes.id9;
_root.fileId10 = titleRepley.firstChild.attributes.id10;
}
}
titleXml.sendAndLoad("http://localhost/xmlbbs/title.asp", titleRepley); // 注释9
}


 
  注释1:创建一个用来发送的XML对象。
  注释2:创建TITLE结点对象。
  注释3:将TITLE结点对象添加到XML对象中。
  注释4:创建一个响应的XML对象。
  注释5:设置响应XML对象的onLoad函数。
  注释6:titlesuccess标示是否从服务器端返回来的XML对象。
  注释7:将返回的标题属性显示在场景的文本框中。
  注释8:将返回的Id号保存在场景的变量中。
  注释9:利用sendAndLoad()函数,将Flash端的XML对象发送到服务器端,并接收从服务器端返回的XML对象。


 

[下一页]


 

  C、Asp端

  新建一个Asp文件,命名为title.asp,输入如下的内容:

 <%
Set MyFileObject = Server.CreateObject("Scripting.FileSystemObject") ‘ 注释1
Set MyTextFile = MyFileObject.CreateTextFile("G:\写作\flashxmlbbs\login.xml", 8, TRUE)
MyTextFile.WriteLine(Request.Form) ‘ 注释2

set objDom = server.CreateObject("microsoft.xmldom") ‘ 注释3
objDom.loadxml(Request.Form) ‘ 注释4
set objname = objdom.documentElement.SelectSingleNode("//TITLE") ‘ 注释5

''判断
set conn=Server.CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/xmlbbs/xmlbbs.mdb") ‘ 注释6
set rs=Server.CreateObject("ADODB.Recordset")
strSql="select * from fileinfo "
rs.open strSql,conn, 1, 1 ‘ 注释7
tempNum = 1
strResult = ""
do until tempNum = 11 ‘ 注释8
if rs.eof then ‘ 注释9
exit do
end if
strResult = strResult & " title" & tempNum & "=""" & rs("title") & """" & " id" & tempNum & "=""" & rs("ID") & """" ‘ 注释10
tempNum = tempNum + 1
rs.movenext ‘ 注释11
loop
rs.close
conn.close

''返回
response.write("<TITLE " & strResult & "></TITLE>") ‘ 注释12
%>
 
  注释1:创建一个文件对象。

  注释2:将从Flash端传送来的XML字符串写在临时文件中。

  注释3:创建一个XML对象。

  注释4:将Flash端传送来的XML字符串导入到XML对象中。

  注释5:创建TITLE结点对象。

  注释6:创建一个数据库的ADO连接,打开数据库。

  注释7:构造一个SQL字符串,在数据库中查询符合条件的记录。   注释8:循环读取Recordset记录集中的记录。

  注释9:如果到了记录集的末尾,退出循环。

  注释10:将从记录集中读出来的记录按格式拼凑成一个字符串。

  注释11:将Recordset记录集中的指针下移一步。

  注释12:将在循环中构造的字符串发送到Flash端。

  三、查看正文

  查看正文,即是在服务器端接收从Flash端发送过来的ID号,根据ID号去查询数据库,将查询的结果用XML格式返回到Flash端。

  A、传递的XML

  1、请求报文

 <FILE ><ID>要查看的主题的ID号</ID></FILE >

  2、响应报文

 <FILE id="id号" title="主题" author="作者" content="内容" reply="回复的内容"></FILE>

  B、Flash端

  1、在第二帧的场景中创建十个按钮,分别将实例命名为“filebtn1”、“filebtn2”、“filebtn3”、“filebtn4”、“filebtn5”、“filebtn6”、“filebtn7”、“filebtn8”、“filebtn9”、“filebtn10”。摆放位置及显示内容如图2所示。

  2、在Button filebtn1的Action Script面板上增加如下的语句:

 on(release){
fileXml1 = new XML(); file://注释1
fileElement1 = fileXml1.createElement("FILE"); file://注释2
idElement1 = fileXml1.createElement("ID"); file://注释3
idNode1 = fileXml1.createTextNode("id");
idNode1.nodeValue = _root.fileId1;
idElement1.appendChild(idNode1); file://注释4
fileElement1.appendChild(idElement1);
fileXml1.appendChild(fileElement1);
_root.fileNowId = _root.fileId1; file://注释5
fileRepley1 = new XML();
fileRepley1.onLoad = onFileReply1; file://注释6
function onFileReply1 (filesuccess1) {
if (filesuccess1) {
_root.filetxt = fileRepley1.firstChild.attributes.title + fileRepley1.firstChild.attributes.author + fileRepley1.firstChild.attributes.content + fileRepley1.firstChild.attributes.reply; file://注释7
_root.gotoAndPlay("content");
}
}
fileXml1.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley1); file://注释8
}

[下一页]


  注释1:创建一个XML对象。
  注释2:创建一个FILE结点对象。
  注释3:创建一个ID结点对象。
  注释4:分别将FILE结点对象和ID结点对象增加到XML对象中去。
  注释5:保存传送的ID号到临时变量。
  注释6:设置onLoad响应函数。
  注释7:将从服务器返回的结果显示出来。
  注释8:利用sendAndLoad()函数,将Flash端的XML对象发送到服务器端,并接收从服务器端返回的XML对象。

  3、在Button filebtn2的Action Script面板上增加如下的语句:

 on(release){
fileXml2 = new XML();
fileElement2 = fileXml2.createElement("FILE");
idElement2 = fileXml2.createElement("ID");
idNode2 = fileXml2.createTextNode("id");
idNode2.nodeValue = _root.fileId2;
idElement2.appendChild(idNode2);
fileElement2.appendChild(idElement2);
fileXml2.appendChild(fileElement2);
_root.fileNowId = _root.fileId2;
fileRepley2 = new XML();
fileRepley2.onLoad = onFileReply2;
function onFileReply2 (filesuccess2) {
if (filesuccess2) {
_root.filetxt = fileRepley2.firstChild.attributes.title + fileRepley2.firstChild.attributes.author + fileRepley2.firstChild.attributes.content + fileRepley2.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml2.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley2);
}
 
  4、在Button filebtn3的Action Script面板上增加如下的语句:

 on(release){
fileXml3 = new XML();
fileElement3 = fileXml3.createElement("FILE");
idElement3 = fileXml3.createElement("ID");
idNode3 = fileXml3.createTextNode("id");
idNode3.nodeValue = _root.fileId3;
idElement3.appendChild(idNode3);
fileElement3.appendChild(idElement3);
fileXml3.appendChild(fileElement3);
_root.fileNowId = _root.fileId3;

fileRepley3 = new XML();
fileRepley3.onLoad = onFileReply3;
function onFileReply3 (filesuccess3) {
if (filesuccess3) {
_root.filetxt = fileRepley3.firstChild.attributes.title + fileRepley3.firstChild.attributes.author + fileRepley3.firstChild.attributes.content + fileRepley3.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml3.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley3);
}

  5、在Button filebtn4的Action Script面板上增加如下的语句:

 on(release){
fileXml4 = new XML();
fileElement4 = fileXml4.createElement("FILE");
idElement4 = fileXml4.createElement("ID");
idNode4 = fileXml4.createTextNode("id");
idNode4.nodeValue = _root.fileId4;
idElement4.appendChild(idNode4);
fileElement4.appendChild(idElement4);
fileXml4.appendChild(fileElement4);
_root.fileNowId = _root.fileId4;

fileRepley4 = new XML();
fileRepley4.onLoad = onFileReply4;
function onFileReply4 (filesuccess4) {
if (filesuccess4) {
_root.filetxt = fileRepley4.firstChild.attributes.title + fileRepley4.firstChild.attributes.author + fileRepley4.firstChild.attributes.content + fileRepley4.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml4.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley4);
}

  6、在Button filebtn5的Action Script面板上增加如下的语句:

 on(release){
fileXml5 = new XML();
fileElement5 = fileXml5.createElement("FILE");
idElement5 = fileXml5.createElement("ID");
idNode5 = fileXml5.createTextNode("id");
idNode5.nodeValue = _root.fileId5;
idElement5.appendChild(idNode5);
fileElement5.appendChild(idElement5);
fileXml5.appendChild(fileElement5);
_root.fileNowId = _root.fileId5;

fileRepley5 = new XML();
fileRepley5.onLoad = onFileReply5;
function onFileReply5 (filesuccess5) {
if (filesuccess5) {
_root.filetxt = fileRepley5.firstChild.attributes.title + fileRepley5.firstChild.attributes.author + fileRepley5.firstChild.attributes.content + fileRepley5.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml5.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley5);
}

  7、在Button filebtn6的Action Script面板上增加如下的语句:

 on(release){
fileXml6 = new XML();
fileElement6 = fileXml6.createElement("FILE");
idElement6 = fileXml6.createElement("ID");
idNode6 = fileXml6.createTextNode("id");
idNode6.nodeValue = _root.fileId6;
idElement6.appendChild(idNode6);
fileElement6.appendChild(idElement6);
fileXml6.appendChild(fileElement6);
_root.fileNowId = _root.fileId6;

fileRepley6 = new XML();
fileRepley6.onLoad = onFileReply6;
function onFileReply6 (filesuccess6) {
if (filesuccess6) {
_root.filetxt = fileRepley6.firstChild.attributes.title + fileRepley6.firstChild.attributes.author + fileRepley6.firstChild.attributes.content + fileRepley6.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml6.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley6);
}


 

[下一页]


 

  8、在Button filebtn7的Action Script面板上增加如下的语句:

 on(release){
fileXml7 = new XML();
fileElement7 = fileXml7.createElement("FILE");
idElement7 = fileXml7.createElement("ID");
idNode7 = fileXml7.createTextNode("id");
idNode7.nodeValue = _root.fileId7;
idElement7.appendChild(idNode7);
fileElement7.appendChild(idElement7);
fileXml7.appendChild(fileElement7);
_root.fileNowId = _root.fileId7;

fileRepley7 = new XML();
fileRepley7.onLoad = onFileReply7;
function onFileReply7 (filesuccess7) {
if (filesuccess7) {
_root.filetxt = fileRepley7.firstChild.attributes.title + fileRepley7.firstChild.attributes.author + fileRepley7.firstChild.attributes.content + fileRepley7.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml7.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley7);
}

  9、在Button filebtn8的Action Script面板上增加如下的语句:

 on(release){
fileXml8 = new XML();
fileElement8 = fileXml8.createElement("FILE");
idElement8 = fileXml8.createElement("ID");
idNode8 = fileXml8.createTextNode("id");
idNode8.nodeValue = _root.fileId8;
idElement8.appendChild(idNode8);
fileElement8.appendChild(idElement8);
fileXml8.appendChild(fileElement8);
_root.fileNowId = _root.fileId8;

fileRepley8 = new XML();
fileRepley8.onLoad = onFileReply8;
function onFileReply8 (filesuccess8) {
if (filesuccess8) {
_root.filetxt = fileRepley8.firstChild.attributes.title + fileRepley8.firstChild.attributes.author + fileRepley8.firstChild.attributes.content + fileRepley8.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml8.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley8);
}

  10、在Button filebtn9的Action Script面板上增加如下的语句:

 on(release){
fileXml9 = new XML();
fileElement9 = fileXml9.createElement("FILE");
idElement9 = fileXml9.createElement("ID");
idNode9 = fileXml9.createTextNode("id");
idNode9.nodeValue = _root.fileId9;
idElement9.appendChild(idNode9);
fileElement9.appendChild(idElement9);
fileXml9.appendChild(fileElement9);
_root.fileNowId = _root.fileId9;

fileRepley9 = new XML();
fileRepley9.onLoad = onFileReply9;
function onFileReply9 (filesuccess9) {
if (filesuccess9) {
_root.filetxt = fileRepley9.firstChild.attributes.title + fileRepley9.firstChild.attributes.author + fileRepley9.firstChild.attributes.content + fileRepley9.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml9.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley9);
}

  11、在Button filebtn10的Action Script面板上增加如下的语句:

 on(release){
fileXml10 = new XML();
fileElement10 = fileXml10.createElement("FILE");
idElement10 = fileXml10.createElement("ID");
idNode10 = fileXml10.createTextNode("id");
idNode10.nodeValue = _root.fileId10;
idElement10.appendChild(idNode10);
fileElement10.appendChild(idElement10);
fileXml10.appendChild(fileElement10);
_root.fileNowId = _root.fileId10;

fileRepley10 = new XML();
fileRepley10.onLoad = onFileReply10;
function onFileReply10 (filesuccess10) {
if (filesuccess10) {
_root.filetxt = fileRepley10.firstChild.attributes.title + fileRepley10.firstChild.attributes.author + fileRepley10.firstChild.attributes.content + fileRepley10.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml10.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley10);
}
 
  12、在场景的第三帧上增加关键帧,并设置此帧的标签为“content”,在此帧的Action Script面板上面增加如下语句:stop();

  利用文本框工具在此帧的场景中拉一个文本框用来显示主题的正文,类型为Dynamic type,var变量设置为“filetxt”。

  C、Asp端

  新建一个Asp文件,保存为file.asp,增加如下的内容:

 <%
Set MyFileObject = Server.CreateObject("Scripting.FileSystemObject") ‘注释1
Set MyTextFile = MyFileObject.CreateTextFile("G:\写作\flashxmlbbs\login.xml", 8, TRUE)
MyTextFile.WriteLine(Request.Form) ‘注释2

set objDom = server.CreateObject("microsoft.xmldom") ‘注释3
objDom.loadxml(Request.Form) ‘注释4
set objid = objdom.documentElement.SelectSingleNode("//FILE/ID") ‘注释5
id = objid.text

''判断
set conn=Server.CreateObject("ADODB.Connection") ‘注释6
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/xmlbbs/xmlbbs.mdb")
set rs=Server.CreateObject("ADODB.Recordset")
strSql="select * from FileInfo where id = " & id ‘注释7
rs.open strSql,conn, 1, 1
title = ""
author = ""
content = ""
if not(rs.bof and rs.eof) then ‘注释8
id = rs("id")
title = rs("title")
author = rs("author")
content = rs("content")
end if

''要单独处理回复
rs.close
reply = ""
strSql="select * from FileInfo where fid = " & id ‘注释9
rs.open strSql,conn, 1, 1
do while not rs.eof
reply = reply & " " & rs("content") ‘注释10
rs.moveNext ‘注释11
loop
rs.close
conn.close
''返回
response.write("<FILE id=""" & id & """ title=""" & title & """ author=""" & author & """ content=""" & content & """ reply=""" & reply & """></FILE>") ‘注释12
%>

  注释1:创建一个临时文件对象。

  注释2:将从Flash端传来的XML字符串写到临时文件中。

  注释3:创建一个XML对象。

  注释4:将Flash端传送来的XML字符串导入到XML对象中。

  注释5:读取XML对象中//FILE/ID结点的内容。

  注释6:创建一个数据库的ADO连接。

  注释7:构造一个SQL字符串,根据传送来的ID号去查询数据库。

  注释8:如果有符合条件的记录,读取相应的记录。

  注释9:回复的帖子的查询条件是Fid,所以要重新查询一下数据库。

  注释10:将查询处理的记录构造成一个字符串。

  注释11:记录集的指针下移一步。

  注释12:构造一个XML格式的字符串,并发送到Flash端。

已有 0 位对此文章感兴趣的网友发布了看法    
我来评两句 登录邮箱: 密码:
  匿名发表
今日推荐
技术文库(共有 46294 篇文章)
操作系统
办公软件
实用知识
网络管理
软件开发
WEB开发
软件工程
数据库
设计在线
信息安全
行业信息化
管理信息化
移动开发
重点推荐
电子杂志订阅
点击电子杂志名称查看样刊
输入E-mail地址即可订阅
E-mail