2013-06-28 64 views
0

我試圖解析:ColdFusion的9解析肥皂導致

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><LoginResponse xmlns="http://services.marketernet.com/application"><LoginResult><results><response value="UY+/9dD+Lz7DT3Oq/WG3CVJ/pFW7o6LEFNA4xOSIWr88Dh2RVAgy9qHP1BwpdiYA"/><exceptions></exceptions></results></LoginResult></LoginResponse></soap:Body></soap:Envelope> 

到目前爲止,我有:

<cfset soapResponse = xmlParse(httpResponse.fileContent) /> 
<cfset results = xmlSearch(soapResponse,"//*[local-name()='LoginResult' and namespace-uri()='http://services.marketernet.com/application']") /> 

我需要我嘗試循環中的<response value="UY+/9dD+Lz7DT3Oq/WG3CVJ/pFW7o6LEFNA4xOSIWr88Dh2RVAgy9qHP1BwpdiYA"/>

值,甚至試圖做一個深層的xml路徑,沒有任何東西。

請幫助我,如果您有任何問題,請讓我知道。

更新1: 「屏幕快照」 ScreenShot

更新2: 「截圖長版」 Screenshot

回答

1

我通常只是用xmlSearch(soapResponse,"//*[local-name()='whatever']"),它爲我工作得很好。它可以返回不同的類型,具體取決於您在XML中搜索的深度。因此,在開發代碼時,我總是使用<cfdump>來查看xmlSearch()函數的結果,以瞭解我正在處理的內容。

我接受了您在ColdFusion 9.0.1上成功共享和測試以下代碼的SOAP響應。請注意,我在這裏有三個不同的搜索,每個搜索都深入到XML樹中。我離開<cfdump>在那裏,所以你可以看到每個回報。

<cftry> 
<cfsavecontent variable="content"> 
    <?xml version="1.0" encoding="UTF-8" ?> 
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
     <soap:Body> 
      <LoginResponse xmlns="http://services.marketernet.com/application"> 
       <LoginResult> 
        <results> 
         <response value="UY+/9dD+Lz7DT3Oq/WG3CVJ/pFW7o6LEFNA4xOSIWr88Dh2RVAgy9qHP1BwpdiYA"/> 
         <exceptions></exceptions> 
        </results> 
       </LoginResult> 
      </LoginResponse> 
     </soap:Body> 
    </soap:Envelope> 
</cfsavecontent> 
<cfset soapResponse = xmlParse(Trim(content)) /> 

<html> 
    <head><title>Test xmlParse</title></head> 
    <body> 
     <h3>xmlParse option 1</h3> 
     <div> 
      <cfset results = xmlSearch(soapResponse,"//*[local-name()='LoginResult']") /> 
      <cfdump var="#results#" /> 
      <cfset value = results[1].results.response.XmlAttributes.value /> 
      <cfdump var="#value#" /> 
     </div> 
     <h3>xmlParse option 2</h3> 
     <div> 
      <cfset results = xmlSearch(soapResponse,"//*[local-name()='results']") /> 
      <cfdump var="#results#" /> 
      <cfset value = results[1].response.XmlAttributes.value /> 
      <cfdump var="#value#" /> 
     </div> 
     <h3>xmlParse option 3</h3> 
     <div> 
      <cfset results = xmlSearch(soapResponse,"//*[local-name()='response']") /> 
      <cfdump var="#results#" /> 
      <cfset value = results[1].XmlAttributes.value /> 
      <cfdump var="#value#" /> 
     </div> 
    </body> 
</html> 
<cfcatch type="any"> 
    <cfdump var="#cfcatch#" /> 
</cfcatch> 
</cftry> 

所有的選項導致從XML的value變量設置爲UY+/9dD+Lz7DT3Oq/WG3CVJ/pFW7o6LEFNA4xOSIWr88Dh2RVAgy9qHP1BwpdiYA