Parsing Soap Responses
Hello,
I am fairly new to CF and am trying to parse and then query a soap response from a third-party api. I have been able to get a response in xml format, but that is where I am stuck. Below the xml response I am getting an error that reads Element.LOGINRESPONSE.LOGINRESULT.XMLTEXT is undefined in LOGINXML.
I realize my code is a mess, but I am just trying out various things. Does anyone have any insight how to get at the Login Response variable in my soap response so that I can query it?
Thanks for any insight!!
<!--- WSDL --->
<cfset wsdl_url="http://somewebsite/sirewebsvc/sire.asmx?wsdl">
<cftry>
<!--- Compose SOAP message to send to Web Service--->
<cfsavecontent variable="soap"><?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<Login xmlns="http://www.siretechnologies.com/">
<LicenseKey>LicenseKey</LicenseKey>
<Username>username</Username>
<Password>password</Password>
<LicenseType>2</LicenseType>
<APIKey>APIKey</APIKey>
<SiteKey></SiteKey>
<CryptKey></CryptKey>
<WebOnly>false</WebOnly>
</Login>
</soapenv:Body>
</soapenv:Envelope>
</cfsavecontent>
<!--- Invoke web service to send message--->
<cfhttp url="#wsdl_url#" method="post" >
<cfhttpparam type="header" name="content-type" value="text/xml">
<cfhttpparam type="header" name="SOAPAction" value="http://www.siretechnologies.com/Login">
<cfhttpparam type="header" name="content-length" value="#len(soap)#">
<cfhttpparam type="header" name="charset" value="utf-8">
<cfhttpparam type="xml" name="message" value="#trim(soap)#">
</cfhttp>
<p><cfoutput>#xmlFormat(cfhttp.fileContent)#</cfoutput> </p>
<cfset MyXML = XmlParse(CFHTTP.FileContent)>
XmlSearch(MyXML, "/LoginResponse/LoginResult/")
<cfcatch type="any">
<cfdump var="#cfcatch#">
</cfcatch>
</cftry>
<cfsavecontent variable="XMLFile"><?xml version="1.0"?>
<LoginResponse>
<LoginResult>
???How do I get this from above, or make it a variable???
</LoginResult>
</LoginResponse>
</cfsavecontent>
<!--- Parse the XML --->
<cfset MyXMLDoc = xmlParse(XMLFile) />
<!--- Dump the XML --->
<h2>Dump</h2>
<cfdump var="#MyXMLDoc#">
<cfset MyNodes = xmlSearch(MyXMLDoc,'/LoginResponse/LoginResult')>
<cfoutput>
<h2>Nodes</h2>
<cfloop from="1" to="#arraylen(MyNodes)#" index="i">
<!--- The array contents need to parsed so you can easily get at the child nodes children and attributes. --->
<cfset LoginXML = xmlparse(MyNodes) />
<b>SessionKey:</b> #LoginXML.LoginResponse.LoginResult.xmltext#<br>
</cfloop>
</cfoutput>
--->
