This content has been marked as final. Show 4 replies
You've stumbled upon a long-standing "known issue" that has plagued CF's xmlSearch function for a long time now. Often times nested namespaces in XML documents cause xmlSearch to fail (or not match).
To get around this, we often just use a quick regex replace statement to trim out name spaces from the entire xml string (before calling xml-parse).
<cfset xmlResponse = reReplace( xmlResponse, '[ ]*xmlns=\"[^\"]*\"', "", "all" )>
Hopefully this will work for you. It's a "hack" I know, but it's the only viable work-around I've heard of.
Thanks for that Grizzly9279.
Removing all namespaces could have detrimental effects later on in your logic.
Since there is more than one namespace in the XML document you supplied, you must qualify all elements when performing an XMLSearch with their namespace, even if it is the default.
Please note the colon in the example above to indicate that the element searched upon is in the default namspace.
The code supplied now returns a structure with 4 keys as expected when applying the modified XPath expression.
A very good point cf_eilloc. That approach works fine when you're dealing with only one namespace (such was the case here), but when you encounter nested namespaces (2 or more deep), you're pretty much screwed and are forced to strip them all out if you want to search the document.
So in general practice, I prefer to simply strip out namespaces altogether unless there is a specific need or purpose of including them in my search.