Ever since I upgraded to ColdFusion 10 I’m discovering a lot of little “gotchas”. Today’s seems to be a change / bug in backwards compatibility of xmlSearch(). ColdFusion 10 added support for XPath 2.0 which adds a lot of great new features I really haven’t played with yet. However, it seems like some things from XPath 1.0 are no longer supported, or just left out of compatibility.
Here is an example. I have a modified Amazon S3 CFC wrapper service that I use. It’s first function that gets xmlSearch() use is a call to “getBuckets”.
Here is the xml being returned:
<xml version="1.0" encoding="UTF-8"?> <ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Owner> <ID>123456789(hidden)</ID> <DisplayName>devPlayground</DisplayName> </Owner> <Buckets> <Bucket> <Name>myDevBucket</Name> 2012-07-11T00:22:33.000Z </Bucket> <Bucket> <Name>myProdBucket</Name> 2012-07-23T17:23:40.000Z </Bucket> </Buckets> </ListAllMyBucketsResult>
This search used to work, but it doesn’t now:
local.buckets = xmlSearch(local.apiCall.response, "//:Bucket");
The above search now throws a dreaded “XMLSearch for Unexpected colon at start of token” error. The namespace didn’t change and this colon was an alias to the namespace as I understand it.
After some searching, I found the answer I needed (as usual) on stackoverflow.
Here is the revised and working xmlSearch():
local.buckets = xmlSearch(local.apiCall.response, "//*[local-name()='Bucket' and namespace-uri()='http://s3.amazonaws.com/doc/2006-03-01/']");
I have a lot of xmlSearch() to fix now..