Question
getting rid of xml formatting, just returning the text in an element
In my code below I need to compare the equality of two
strings, but I cant seem to get rid of the xml encoding. What
method do I use to strip just the xmlText from the xml object.
ToString doesn't seem to work. When i finally compare them, that
does not make sense either, because CF is returning -1 which is
described in the docuemntation to mean that string1 (70 chars) is
smaller than string2 (12 chars). Whats going on?
thanks.
<cfif fileExists(#xmlFile#)>
<cfset users = XmlParse(xmlFile)>
<cfloop index="allUsers" array="#XmlSearch( users, '/company/user/username')#">
<cfset jed = "JedSchneider">
<p>
<cfoutput>#jed#, The length of the string #Len(jed)#</cfoutput><br>
<!--- returns: "JedSchneider, The length of the string 12" --->
<cfoutput>#allUsers.#, The length of the string #Len(allUsers)#</cfoutput><br>
<!--- returns: "JedSchneider, The length of the string is 72" --->
<!--- The cause of the 72 chars... in raw html you have the following--->
<!--- <?xml version="1.0" encoding="UTF-8"?> <username>JedSchneider</username> --->
<cfset UsernameCompare = Compare(#allUsers#, #jed#)>
<cfoutput>#UsernameCompare#</cfoutput>
<!--- returns: -1, string1 is smaller than string2 --->
</p>
</cfloop>
<cfelse>
<cfoutput>Bad news, #xmlFile# file doesn't exist</cfoutput>
</cfif>
thanks.
<cfif fileExists(#xmlFile#)>
<cfset users = XmlParse(xmlFile)>
<cfloop index="allUsers" array="#XmlSearch( users, '/company/user/username')#">
<cfset jed = "JedSchneider">
<p>
<cfoutput>#jed#, The length of the string #Len(jed)#</cfoutput><br>
<!--- returns: "JedSchneider, The length of the string 12" --->
<cfoutput>#allUsers.#, The length of the string #Len(allUsers)#</cfoutput><br>
<!--- returns: "JedSchneider, The length of the string is 72" --->
<!--- The cause of the 72 chars... in raw html you have the following--->
<!--- <?xml version="1.0" encoding="UTF-8"?> <username>JedSchneider</username> --->
<cfset UsernameCompare = Compare(#allUsers#, #jed#)>
<cfoutput>#UsernameCompare#</cfoutput>
<!--- returns: -1, string1 is smaller than string2 --->
</p>
</cfloop>
<cfelse>
<cfoutput>Bad news, #xmlFile# file doesn't exist</cfoutput>
</cfif>
