XMLSearch supports the contains string function of XPath

August 18, 2008

ColdFusion 8 added improved support for XPath expressions. I've just discovered that you can now use the contains string function of XPath with XmlSearch!

Here's a simple example; imagine you wanted to find all the pizzas that use basil as an ingredient.

<cfxml variable="xmlobject">
  <evening_menu>
    <pizza>
      <name>Margherita</name>
      <ingredients>tomato, mozzarella, basil</ingredients>
    </pizza>
    <pizza>
      <name>Capricciosa</name>
      <ingredients>mozzarella, tomato, mushrooms, artichokes, ham, olives, egg</ingredients>
    </pizza>
    <pizza>
      <name>Quattro Formaggi </name>
      <ingredients>tomato, mozzarella, stracchino, fontina, gorgonzola, basil</ingredients>
    </pizza>
  </evening_menu>
</cfxml>
  
<cfdump var="#XmlSearch(xmlobject, "/evening_menu/pizza/ingredients[ contains(., 'basil' ) ] ")#" />

 


3 comments

  1. XML searching is awesome :)

    Comment by Ben Nadel – August 18, 2008
  2. While that's very helpful, it would REALLY be great if they swapped out the XALAN processor in favor of the SAXON processor to get us XSLT 2.0 support. That's on my wishlist for CF9.

    Comment by Mike Rankin – August 18, 2008
  3. @Ben, I'm really glad to see ColdFusion improving support as using XPath before was always a frustrating experience!

    @Mike, that's a great idea!

    Comment by John Whish – August 19, 2008

Leave a comment

If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)

Please note: If you haven't commented before, then your comments will be moderated before they are displayed.