2 Replies Latest reply on Oct 28, 2009 1:22 PM by ACI_CF

    XMLSearch case sensitivity


      I'm trying to do a query using xmlsearch, but it is case sensitive as to the text being searched. If you do a search for "network" it does not return anything, however if you do a search on "Network" it returns the data. How can you get the search not to be case sensitive and to return the data regardless of the case?  (code is below)



      <cfhttp url="http://www.server/webpage.cfm" method="GET">

      <CFSet xml=CFHTTP.FileContent>
      <CFSet xmlDoc = XMLParse(xml)>

      <cfset results = XMLSearch(xmlDoc, "//job[TITLE_STRING='#form.JobTitle#']")/>

        • 1. Re: XMLSearch case sensitivity
          Adam Cameron. Level 5

          See my comment on Ben Nadel's blog: http://www.bennadel.com/blog/1491-Ask-Ben-Finding-XML-Nodes-That-Have-Children-With-The-Gi ven-Case-Insensitive-Phrase.htm.



          There's another couple of options here Ben:

          <cfset aNoCase1 = xmlSearch(xmlFeed, "//item[contains(translate(title/text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'coldfusion')]")>

          It's a bit long-winded, but it works.

          This next one conditionally works... it's OK for looking up the count of results, but as it transforms the XML, one has to be cautious with what one does with the results:

          <cfset aNoCase2 = xmlSearch(lcase(xmlFeed), lcase("//item[contains(title/text(), 'COLDFusion')]"))>

          Another note here is that the the nodes in the resultant array are not references to the original nodes, they're references to a separate XML doc which is created by the lcase(xmlFeed) operation. So one cannot update the nodes in the array and expect to see the updates in the original doc (like one usually would). So this one comes with some caveats, but if those are not a concern: it's an adequate approach.




          1 person found this helpful
          • 2. Re: XMLSearch case sensitivity
            ACI_CF Level 1

            I ended up going with another method over the xmlsearch for this. I've included the code below


            <CFSet xml=CFHTTP.FileContent>
            <CFSet xmlDoc = XMLParse(xml)>
            <cfset jobs = xmldoc.root.XmlChildren>
            <cfset size = ArrayLen(jobs)>


            <!--- create a query object with the job data --->
            <cfset myquery = QueryNew("JobID, Title") >
            <cfset temp = QueryAddRow(myquery, #size#)>
            <cfloop index="i" from = "1" to = #size#>
                <cfset temp = QuerySetCell(myquery, "JobID",
                    #xmldoc.root.job[i].jobpostingid_int.XmlText#, #i#)>
                <cfset temp = QuerySetCell(myquery, "Title",
                    #LCase(xmldoc.root.job[i].TITLE_STRING.XmlText)#, #i#)>



            <!--- Select entries with the Title name starting with N and dump the result --->
            <cfquery name="ImqTest" dbType="query">
               SELECT JobID, Title
               FROM myquery