Coldfusion 9解析Soap结果
我试图解析:Coldfusion 9解析Soap结果,soap,coldfusion,coldfusion-9,cfml,Soap,Coldfusion,Coldfusion 9,Cfml,我试图解析: <?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><Log
<?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']") />
我需要
我尝试循环,甚至尝试做深层xml路径,什么都不做
请帮助我,如果你有问题请告诉我
更新1:“截图”
更新2:“截图长版”
我通常只使用
xmlSearch(soapResponse,“/*[local-name()='whatever'])
,对我来说效果很好。它可以返回不同的类型,具体取决于在XML中搜索的深度。因此,在开发代码时,我总是使用
查看xmlSearch()
函数的结果,以了解我在处理什么
我接受了您共享的SOAP响应,并在ColdFusion 9.0.1上成功地测试了以下代码。请注意,这里有三种不同的搜索,每种搜索都深入到XML树中。我把
放在那里,这样你就可以看到每个返回的内容了
<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>
测试xmlParse
xmlParse选项1
xmlParse选项2
xmlParse选项3
所有选项都会导致从XML中将值设置为UY+/9dD+Lz7DT3Oq/WG3CVJ/pFW7o6LEFNA4xOSIWr88Dh2RVAgy9qHP1BwpdiYA