Just a quick post while it's fresh on my mind as I'm sure this is going to crop up in the future as I don't often handle XML in Coldfusion.
Basically here is the scenario. You have an XML file which isn't that complicated in structure but whatever you do XMLSearch just won't return the results you expect - it appears broken.
Here is an example from the Spotify API:
<artists xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.spotify.com/ns/music/1">
<opensearch:Query role="request" startPage="1" searchTerms="Ash"/>
Ok, in the above let's say I wan't to get all artists from the XML using xmlSearch.
The usual way would be to specify the following:
<cfset artists = xmlSearch(xml,"/artists/artist")>
This *should* work fine - top level 'artist' node, followed by some 'opensearch' and 'artist' nodes. We should now have an array of artist nodes in our artists variable. But we don't. Why?
Well the simple answer is, look closely at the artist node. Notice the xmlns attributes? They define an XML namespace and throw the whole thing out of whack. Ok, it's part of the spec but to get around this with XMLSearch we need to change our call to the following:
Simple change but this tells the command to ignore the namespace and just return all 'artist' nodes that sit underneath the 'artists' node.
A simple distinction but one that can save hours of hair tearing. :)