XMLSearch and empty arrays with namespaces

I ran into an odd issue today and I'm documenting it here for my own future knowledge. When searching an XML document with defined namespaces on elements, XMLSearch wasn't returning any results. Take the following example: Dan Short 5 Angela Buraglia 10 The result of this is unexciting... XPathFirstRun.png The array *should* have all of the results from my person search. Unfortunately the namespace is mucking everything up... A little Google searching got me to a post from Jeremy Gibbens showing how to get around the namespace issue. You need to search by the local name of the node instead, like so: This gives a much more satisfying result: XMLPathSecondRound.png Have fun searching your XML!
Posted by Daniel Short on Feb 12, 2009 at 1:29 PM | Categories: ColdFusion -

3 Comments

Ben Nadel

Ben Nadel wrote on 02/13/09 9:11 AM

Local-name() for the win! I used to feel that this was really hacky (and still do a bit), but it the easiest way to deal with it and has helped me out so many times!
Daniel Short

Daniel Short wrote on 02/13/09 9:21 AM

Yep, it's hacky, but tasty :)
Chris Hampton

Chris Hampton wrote on 08/19/10 3:05 PM

I could buy you a drink right now! I've spent the last two hours looking for a working solution to this problem.