ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
客户端(javascript+dom)<---------ajax<----------服务器端的xml信息 ajax负责请求xml和接收xml信息,dom负责处理xml信息 <body> <div id="result"></div> </body> <script> var xhr=new XMLHttpRequest(); xhr.onreadystatechange=function(){ if(xhr.readyState==4) { var xmldom=xhr.responseXML; var msgs=xmldom.getElementsByTagName('msg'); var s=''; for(var i=0;i<msgs.length;++i) { var sder=msgs\[i\].getElementsByTagName('sender')\[0\].firstChild.nodeValue; var jie=msgs\[i\].getElementsByTagName('jie')\[0\].firstChild.nodeValue; var cnt=msgs\[i\].getElementsByTagName('content')\[0\].firstChild.nodeValue; s+="发送者:"+sder+".接收者:"+jie+".消息:"+cnt+"<br />"; } document.getElementById('result').innerHTML=s; } } xhr.open('get','./test.xml'); xhr.send(null); </script> <?xml version="1.0" encoding="utf-8" ?> <messages> <msg> <sender>tom</sender> <jie>mary</jie> <content>晚上一起去吃饭吧</content> </msg> <msg> <sender>mary</sender> <jie>tom</jie> <content>不吃了,要去打球</content> </msg> </messages>