客户端
<scriptlanguage="javascript">
//生成XML文件
functionGetAllFormData()
{
varstrXML="<Client>rn<FormData>rn";
strXML+="<UserName>bccu</UserName>"
strXML+="<Age>25</Age>";
strXML+="</FormData>rn</Client>"
returnstrXML;
}
///向服務器发送XML文档
functionSend(Str,URL)
{
varHttp=newActiveXObject("Microsoft.XMLHTTP")
Http.open("POST",URL,false)
Http.send(Str)
returnHttp.responseText;
}
///获得XML中指定的节的值
functionGetXMLNodeValue(strXML,nodeName)
{
varDom=newActiveXObject("Microsoft.XMLDOM")
Dom.async=false
Dom.loadXML(strXML)
if(Dom.parseError.errorCode!=0)
{
delete(Dom)
return(false)
}
else
{
varnode=Dom.documentElement.selectSingleNode("//"+nodeName);
if(node)
nodeValue=node.text;
delete(Dom)
return(nodeValue);
}
}
functionTest()
{
vartmp=Send(GetAllFormData(),"./test.aspx");
varname=GetXMLNodeValue(tmp,"UserName");
varpassword=GetXMLNodeValue(tmp,"Age");
}
</script>
服务器端(test.cs)
System.IO.Streamstream=Request.InputStream
System.Xml.XmlDocumentdoc=newXmlDocument();
try
{
doc.Load(stream);//加载发送过来的Xml文档
}
catch
{
byte[]buffer=newbyte[stream.Length];
stream.Read(buffer,0,buffer.Length);
stringstrXML=System.Text.UnicodeEncoding.Default.GetString(buffer,0,buffer.Length);
doc.LoadXml(strXML);
}
//将doc处理后输出以便返回到客户端(此处省略)
response.write("")