<%@ Language=VBScript %> <% Option Explicit Class cTest dim str 'str="print success!" sub print() 'dim str str="print success!" response.Write (str) End sub End Class sub submitTest() response.write("URL="&Request.ServerVariables("URL")&"</br>") response.write("QUERY_STRING="&Request.ServerVariables("QUERY_STRING")&"</br>") response.write("<form NAME='form' ACTION='ErrTest.asp' METHOD='get'>") response.write("<input type='hidden'name='hid' value='test'>") response.write("<input type='submit'name='btn' value='按钮提交'>") response.write("</form>") end sub Function SendSoaRequest(xmlResponse,requestType) dim returnValue,obj,ResponseInfo set obj = new Cls_SOA_Service with obj '.UserId="110254" .UserId="Customer.WSUser" '! .RequestType = requestType .requestXML = xmlResponse If .Request then returnValue = .ObjXmlDoc.text else returnValue = "" end if end with SendSoaRequest = returnValue End Function function getSOA() dim requestType,xmlResponse,xmlRequest,strXML,res requestType = "Customer.User.Service.GetAllianceInfoFromSession" xmlRequest= "<GetAllianceInfoFromSessionRequest>" xmlRequest = xmlRequest & "<Session>_zh_baidu</Session>" xmlRequest = xmlRequest & "<AllianceID>1</AllianceID>" xmlRequest = xmlRequest & "<SmartLinkHost>http://www.sina.com.cn</SmartLinkHost>" xmlRequest = xmlRequest &"</GetAllianceInfoFromSessionRequest>" '调用soa接口 xmlResponse = SendSoaRequest(xmlRequest,requestType) response.Write (xmlResponse&"</br>") '-- 'xmlResponse = "<Response>" 'xmlResponse = xmlResponse &"<Header ShouldRecordPerformanceTime=""false"" UserID=""480106"" RequestID=""8d65038a-dd5b-47e6-8e31-4f9e176f761d"" ResultCode=""Success"" ServerIP=""192.168.81.72"" />" 'xmlResponse = xmlResponse &" <GetAllianceInfoFromSessionResponse>" 'xmlResponse = xmlResponse &" <ProcessFlag>T</ProcessFlag>" 'xmlResponse = xmlResponse &" <AllianceID>1</AllianceID>" 'xmlResponse = xmlResponse &" <SID>449</SID>" 'xmlResponse = xmlResponse &" <Ouid />" 'xmlResponse = xmlResponse &" <Session>U449</Session>" 'xmlResponse = xmlResponse &" </GetAllianceInfoFromSessionResponse>" 'xmlResponse = xmlResponse &"</Response>" 'XML处理 res= CreateXML(xmlResponse) End function '=调用============== Dim iRetCode,iAlliance_RVPID_Out,iAlliance_RVPID_in Dim sEid,iAllianceID,dtDataChange_lastTime,sEidName 'Form提交测试 'call submitTest() 'SOA测试 'call getSOA() '类测试(作用域) 'dim obj 'set obj =new cTest 'call obj.print() '------------------------------------------------------------------------- 'XML解析 遍历测试! dim strXML strXML="" strXML=strXML & "<bookstore>" strXML=strXML & " <book category=""children"">" strXML=strXML & " <title lang=""en"">Harry Potter</title>" strXML=strXML & " <author>J K. Rowling</author>" strXML=strXML & " <year>2005</year>" strXML=strXML & " <price>29.99</price>" strXML=strXML & " </book>" strXML=strXML & " <book category=""cooking"">" strXML=strXML & " <title lang=""en"">Everyday Italian</title>" strXML=strXML & " <author>Giada De Laurentiis</author>" strXML=strXML & " <year>2005</year>" strXML=strXML & " <price>30.00</price>" strXML=strXML & " </book>" strXML=strXML & " <book category=""web"" cover=""paperback"">" strXML=strXML & " <title lang=""en"">Learning XML</title>" strXML=strXML & " <author>Erik T. Ray</author>" strXML=strXML & " <year>2003</year>" strXML=strXML & " <price>39.95</price>" strXML=strXML & " </book>" strXML=strXML & " <book category=""web"">" strXML=strXML & " <title lang=""en"">XQuery Kick Start</title>" strXML=strXML & " <author>James McGovern</author>" strXML=strXML & " <author>Per Bothner</author>" strXML=strXML & " <author>Kurt Cagle</author>" strXML=strXML & " <author>James Linn</author>" strXML=strXML & " <author>Vaidyanathan Nagarajan</author>" strXML=strXML & " <year>2003</year>" strXML=strXML & " <price>49.99</price>" strXML=strXML & " </book>" strXML=strXML & "</bookstore>" '解析 call analyseXML(strXML) Function analyseXML(strXML) dim retXml,requestInfo,nodes set requestInfo = Server.CreateObject("msxml2.DOMDocument") requestInfo.validateOnParse = false requestInfo.async = false requestInfo.loadXML(strXML) 'root节点 dim rootNode Set rootNode = requestInfo.selectSingleNode("bookstore") 'book节点列表 dim bookNodes,titleNode,textNode Set bookNodes = rootNode.childNodes dim Node,iLoop,jLoop for each Node in bookNodes response.Write ("<book ") for iLoop=0 to Node.attributes.length-1 if (Node.attributes(jLoop).nodetype=2) then response.Write (Node.attributes(iLoop).name&"="""&Node.attributes(iLoop).value&""" ") end if next response.Write ("><br>") iLoop=0 'response.Write (Node.ChildNodes.length &" ") for iLoop=0 to Node.ChildNodes.length-1 response.Write (" <"&Node.ChildNodes(iLoop).nodename) for jLoop=0 to Node.ChildNodes(iLoop).attributes.length-1 if (Node.attributes(jLoop).nodetype=2) then response.Write (" "&Node.ChildNodes(iLoop).attributes(jLoop).name&"="""&Node.ChildNodes(iLoop).attributes(jLoop).value&""" ") end if next response.Write (">" & Node.ChildNodes(iLoop).text) response.Write ("</"&Node.ChildNodes(iLoop).nodename&"></br>") next response.Write ("</book></br>") next ''-------------------------------------------------------------------- ''第4个book的第3个节点 i=3,j=2 'dim i,j 'i=3 'j=2 'response.Write ("</br>nodename=" & bookNodes.item(i).ChildNodes(j).nodename & ",text=" & bookNodes.item(i).ChildNodes(j).text & "</br>") 'response.Write ("</br>nodename=" & bookNodes.item(i).ChildNodes(j).nodename & ",text=" & bookNodes.item(i).ChildNodes(j).text & "</br>") ''属性 'dim bookNode_n,attr 'Set bookNode_n = rootNode.childNodes.item(3) 'Set attr = bookNode_n.attributes.getNamedItem("category") '--注意大小写 'response.Write ("Attribute="&attr.Value) '-------------------------------------------------------------------- End Function Function CreateXML(xmlResponse) 'xmlResponse= "<GetAllianceInfoFromSessionResponse>" 'xmlResponse = xmlResponse &" <ProcessFlag>T</ProcessFlag>" 'xmlResponse = xmlResponse &" <AllianceID>1</AllianceID>" 'xmlResponse = xmlResponse &" <SID>449</SID>" 'xmlResponse = xmlResponse &" <Ouid />" 'xmlResponse = xmlResponse &" <Session>U449</Session>" 'xmlResponse = xmlResponse &"</GetAllianceInfoFromSessionResponse>" if xmlResponse="" then CreateXML="" else dim retXml,requestInfo,nodes set requestInfo = Server.CreateObject("msxml2.DOMDocument") requestInfo.validateOnParse = false requestInfo.async = false requestInfo.loadXML(xmlResponse) If ucase(requestInfo.selectSingleNode("/Response/Header/@ResultCode").Value)="SUCCESS" then dim iAllianceId,iSid iAllianceId=requestInfo.selectSingleNode("/Response/GetAllianceInfoFromSessionResponse/AllianceID").text iSid =requestInfo.selectSingleNode("/Response/GetAllianceInfoFromSessionResponse/SID").text response.Write ("iAllianceId="&iAllianceId&",iSid="&iSid) End If End if End Function %>