【问题标题】:msxml Parsing Soap Response using MS DOM and classic aspmsxml 使用 MS DOM 和经典 asp 解析 Soap 响应
【发布时间】:2010-11-04 15:49:48
【问题描述】:

我使用的是经典的“ASP”,不要骗我。只是还没能跳到.Net。我只是在学习肥皂,并成功地创建了一个对 web 服务的 SOAP 请求。但是,我无法弄清楚如何解析响应并拉出单个节点。我正在使用 MS DOM 将响应加载到文档中。我可以得到屏幕的响应。我尝试了以下方法,但无法单独访问任何 nodes_text。

'Set the XML Object 
Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")

'Set Asynchoronous = false
xmlDoc.async = False

'Load the XML file.
'User Server.MapPath method is the XML is located in your site.
'Else you can use the absolute path.

xmlDoc.Load (strResult)

'If there is any errors pasring the file the notify

If xmlDoc.parseError.errorCode = 0 Then

Response.Write "Error Parsing XML"

Response.Write  "Rason :" & xmlDoc.parseError.reason & "Error Line: " & xmlDoc.parseError.line

End If

'Get ALL the Elements by the tag name book

Set sessionid = xmlDoc.getElementsByTagName("session_id")

'Now Iterate through the List and Display
response.write"sessionid ="&sessionid&"<BR>"
 For i = 0 to (sessionid.Length-1)
    Response.Write "session_id " & sessionid.item(i).childNodes(0).text  & "<br/>"

Next

这是我正在尝试解析的响应

<ns:getSessionResponse xmlns:ns="http://services.axis.openmeetings.org">
    <ns:return xmlns:ax217="http://basic.beans.data.app.openmeetings.org/xsd" 
               xmlns:ax218="http://basic.beans.hibernate.app.openmeetings.org/xsd" 
               type="org.openmeetings.app.hibernate.beans.basic.Sessiondata">
        <ax218:id>71</ax218:id>
        <ax218:language_id xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
        <ax218:organization_id xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
        <ax218:refresh_time>2010-11-04T15:17:13.717Z</ax218:refresh_time>
        <ax218:sessionXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
        <ax218:session_id>5f0415d9cdb72681816095debf3735de</ax218:session_id>
        <ax218:starttermin_time>2010-11-04T15:17:13.717Z</ax218:starttermin_time>
        <ax218:storePermanent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
        <ax218:user_id xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
    </ns:return>
</ns:getSessionResponse>

我需要从这个部分中提取 session_id,但似乎无法做到。是的,我希望尽快迁移到 .NET。

【问题讨论】:

  • 响应示例的格式似乎在翻译中丢失了。能否再次包含 XML 响应?

标签: msxml


【解决方案1】:

如果 strResult 是 xml 文件的 URL,那么您可以使用:

xmlDoc.Load(strResult)

但是如果strResult代表xml的内容,则需要使用:

xmlDoc.LoadXML(strResult)

更多信息请参考MSDN

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多