【问题标题】:Coldfusion 9 Parse Soap resultsColdfusion 9 Parse Soap 结果
【发布时间】:2013-06-28 17:06:25
【问题描述】:

我正在尝试解析:

<?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']") />

我需要&lt;response value="UY+/9dD+Lz7DT3Oq/WG3CVJ/pFW7o6LEFNA4xOSIWr88Dh2RVAgy9qHP1BwpdiYA"/&gt;的值

我尝试循环,甚至尝试做一个深层的xml路径,什么都没有。

请帮助我,如果您有任何问题,请告诉我。

更新 1:“屏幕截图”

更新 2:“截图长版”

【问题讨论】:

    标签: soap coldfusion coldfusion-9 cfml


    【解决方案1】:

    我通常只使用xmlSearch(soapResponse,"//*[local-name()='whatever']"),它对我来说很好用。根据您在 XML 中搜索的深度,它可以返回不同的类型。因此,在开发代码时,我总是使用&lt;cfdump&gt; 来查看xmlSearch() 函数的结果以了解我在处理什么。

    我采用了您共享的 SOAP 响应,并在 ColdFusion 9.0.1 上成功测试了以下代码。请注意,我在这里进行了三个不同的搜索,每个搜索都深入研究了 XML 树。我把&lt;cfdump&gt; 留在了那里,这样你就可以看到每个返回的内容。

    <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

    【讨论】:

      猜你喜欢
      • 2013-05-13
      • 2012-08-10
      • 2011-10-13
      • 2011-04-02
      • 1970-01-01
      • 1970-01-01
      • 2018-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多