For example, please consider the following code snippet:
Scenario 1:
The company name I received as a part of SOAP response is as follows:
<Company>Amazon, Inc </Company>
Scenario 2:
Another company name I received as a part of SOAP response is as follows:
<Company>Google, Inc </Company>
Basically, from the user end I am inputting some information and based on that I am getting different company names inside the <Company>
tag.
The following code shows how I am storing the response in XMLResponse variable
<cfset XMLResponse = XmlParse(
httpResponse.fileContent.Trim()
) />
The following piece of code shows how I am parsing the response and storing the content in a variable:
<cfset arrCOMPANY = XmlSearch(
XMLResponse,
"//*[name()='Company']"
) />
So now I have arrCOMPANY = Amazon, Inc is I happen to be in Scenario and Google, Inc otherwise.
My Question:
I have to insert these data into the database based on the company name and set an integer field to be equal to 1 if the company name is Amazon,Inc and set it to zero otherwise for all other companies.
Please let me know if I am following the right path:
I am thinking of writing two cfqueries based on the company names and hence I am thinking to place the following condition :
<cfif arrCompany eq "Amazon, Inc">
// Here I will write cfquery with an integer field = 1
Or
<cfif arrCompany eq "Google, Inc">
// Here I will write cfquery with integer field 0
So, am I doing the right comparision, I am wondering whether the company names that I am comparing with eq sign will be actually compared or not as it contains spaces after first word ( say for example the space between Amazon, and Inc).
Please share your experience.
Thanks
Here is what I did:
I have applied trim function on specific element as well. For example:
The Value in the CompanyName variable is Amazon, Inc
<cfset CompanyName = Trim(arrCompany[1])> // adding index 1 because it's a complex structure
Here is how I am trying to use cfif condition:
<cfif CompanyName eq "Amazon, Inc">
<cfset m = 1>
<cfelse>
<cfset m = 0>
</cfif>
<cfoutput>#m#</cfoutput>
Despite doing above, I am getting 0
as my output. Please let me know if I am comparing wrong.
Amazon, Inc
it will be considered equal. Is something different happening in your actual code? – Pratincole