以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XML源码及示例(仅原创和转载) 』  (http://bbs.xml.org.cn/list.asp?boardid=32)
----  利用xml(xmldom,xmlhttp)进行客户机与服务器的数据交互遇到的问题??  (http://bbs.xml.org.cn/dispbbs.asp?boardid=32&rootid=&id=7057)


--  作者:wedge
--  发布时间:4/27/2004 2:01:00 PM

--  利用xml(xmldom,xmlhttp)进行客户机与服务器的数据交互遇到的问题??
利用xmlhttp发送一个book. xml文档给服务器端的gettitle.asp文件,在服务器端对接受来的xml文档利用DOM转换成另一个形式的xml文档,返回给客户端。利用onreadystatechange检查服务器的状态,成功解析后执行showelement函数。
但没有显出预期的效果,请高手指点一下。
book.xml
**********************
<?xml version="1.0" encoding="GB2312"?>
<booklist>
 <book sales="Y">
  <code>F8915</code>
  <title>ASP网页制作彻底研究</title>
  <authorlist>
   <author>陈会安</author>
   <author>sun</author>
  </authorlist>
  <price>580</price>
 </book>
 <book sales="Y">
  <code>F8916</code>
  <title>ASP与IIS 4/5网站架设彻底研究</title>
  <authorlist>
   <author>wedge</author>
   <author>sun</author>
  </authorlist>
  <price>550</price>
 </book>
 <book sales="N">
  <code>F8917</code>
  <title>ASP精讲案例教程</title>
  <authorlist>
   <author>wedge</author>
   <author>sun</author>
  </authorlist>
  <price>590</price>
 </book>
 <book sales="N">
  <code>F8918</code>
  <title> 家常小菜</title>
  <authorlist>
   <author>sally</author>
   <author>sun</author>
  </authorlist>
  <price>120</price>
 </book>
 </booklist>

***************************
onreadystatechange.htm
*********************************************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>onreadystatechange</title>
</head>

<body>
<script language="JavaScript">
var xmldom=new ActiveXObject("MSXML2.DOMDocument.4.0")
xmldom.async="false"
xmldom.load("book.xml")
if(!xmldom.parseError.errorCode)
{
var xmlhttp=new ActiveXObject("MSXML2.XMLHTTP.4.0")
xmlhttp.onreadystatechange=showelement
xmlhttp.open("POST","gettitle.asp",true)
xmlhttp.send(xmldom)
}
else
{
document.write(xmldom.parseError.reason+"<br>")
}


function showelement()
{if (xmlhttp.readyState==4)
{
xmlresult=xmlhttp.responseXML
var objnode=xmlresult.documentElement.childNodes
stroutput="<TABLE border=1>"
for (i=0;i<objnode.length;i++)
{stroutput=stroutput+"<tr><td>"+objnode.item(i).text+"</td></tr>"}
result.innerHTML=stroutput+"</TABLE>"
}
}
</script>
<div id="result"></div>
</body>
</html>
***********************************************
gettitle.asp
**********************************************
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
response.ContentType="text/xml"
response.Expires=0
dim xmldom,strtitle,objnode
set xmldom=Server.CreateObject("MSXML2.DOMDocument.4.0")
xmldom.async="false"
xmldom.load(request)
response.Write("<?xml version='1.0' encoding='gb2312'?>")
response.Write("<titlelist>")
for each objnodelist in xmldom.documentElement.childNodes
  for each objnode in objnodelist.childNodes
    if objnode.nodename="title" then
 strtitle=objnode.text
response.Write("<title>"&strtitle&"</title>")
end if
next
next
response.Write("</titlelist>")
set xmldom=nothing
%>


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
125.000ms