Copy link to clipboard
Copied
How do you create a wildcard search using xmlsearch? Or a search that will return records matching some of the words entered in the query (in other words the query does not require the exact text to be entered to return the record.)? For example, if I want to search for "Network Support Technician" I cannot enter "Network Support" and get the results to come up, I'll have to enter "Network Support Technician" to get any results. (code is below)
<cfhttp url="http://www.server/webpage.cfm" method="GET">
</CFHTTP>
<CFSet xml=CFHTTP.FileContent>
<CFSet xmlDoc = XMLParse(xml)>
<cfset results = XMLSearch(xmlDoc, "//job[TITLE_STRING='#form.JobTitle#']")/>
Copy link to clipboard
Copied
xpath 1.0 supports a range of string functions. It's perhaps an idea to have a read through this: http://www.w3.org/TR/xpath. Or perhaps if you want something slightly less impenetrable: http://www.w3schools.com/XPath/xpath_functions.asp.
--
Adam
Copy link to clipboard
Copied
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.jobpostingid_int.XmlText#, #i#)>
<cfset temp = QuerySetCell(myquery, "Title",
#LCase(xmldoc.root.job.TITLE_STRING.XmlText)#, #i#)>
</cfloop>
<!--- Select entries with the Title name starting with N and dump the result --->
<cfquery name="ImqTest" dbType="query">
SELECT JobID, Title
FROM myquery
where Title LIKE '#LCase(form.JobTitle)#%'
</cfquery>