XPath Support Expanded In ColdFusion 8

Posted November 2, 2007 at 8:19 AM by Ben Nadel

Tags: ColdFusion

I was just reading about some ColdFusion XPath functionality over on Anuj Gakhar's blog. One of the things that he demonstrated was that XmlSearch() could return things like count() and sum() on a node set. I was a little shocked that I had missed this as part of my XPath and XmlSearch() ColdFusion Tutorial. So, naturally, I went and tried it on my test server:

  • <!--- Create an XML document. --->
  • <cfxml variable="xmlData">
  •  
  • <data>
  • <datum>1.1</datum>
  • <datum>3.2</datum>
  • <datum>4.5</datum>
  • <datum>7.8</datum>
  • <datum>10.9</datum>
  • </data>
  •  
  • </cfxml>
  •  
  •  
  • <!--- Get the sum of node values. --->
  • <cfset arrNodes = XmlSearch(
  • xmlData,
  • "sum( //datum )"
  • ) />
  •  
  • <!--- Dump out resultant nodes. --->
  • <cfdump var="#arrNodes#" />

Running this, we get the following output:

27.5

Unbelievable! It worked.

After the shock of having missed this in my initial research wore off a bit, I realized that I was viewing the page as a ColdFusion 8 page (which we have running on an alternate port). Switch the page over to the ColdFusion 7 port and running the page again, I got the following ColdFusion error:

An error occured while Transforming an XML document. Can not convert #NUMBER to a NodeList!

Ahhh, that's what I am used to. Looks like ColdFusion 8 has beefed up the XPath support. And, indeed, looking at the ColdFusion 8 livedocs, I see this in the History:

History
ColdFusion 8: Added support for returning any valid XPath result, not just arrays of XML object nodes.

This is good to know. XPath and XmlSearch() are some very powerful tools to have in the tool belt, and it looks like ColdFusion 8 is making them even more powerful. Man, I love this language!



Reader Comments

Aug 6, 2011 at 3:18 PM // reply »
10 Comments

I am working on some XPath stuff right now. Thanks for the help!


Nov 30, 2011 at 5:11 PM // reply »
11 Comments

Does anyone happen to know what specific version of xPath ColdFusion 8.0.1 uses?

(Trying to pin down which xPath features CF 8 supports...)

Thanks.


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Jun 18, 2013 at 9:20 PM
Mapping AngularJS Routes Onto URL Parameters And Client-Side Events
I couldn't find examples of passing multiple arguments using the when() routing statement so figured out through trial and error that you can pass multiple arguments using the following format: .whe ... read »
Jun 18, 2013 at 3:39 PM
Experimenting With The Amazon Simple Storage Service (S3) API Using ColdFusion
Hi Ben, THANKS! While not bleeding edge, it is new to me & I like learning new things every day! ... read »
Jun 18, 2013 at 12:30 PM
Disabling Auto-Correct And Auto-Capitalize Features On iPhone Inputs
Also spellcheck="false" should be mentioned as part of html5 specs ... read »
Jun 18, 2013 at 8:40 AM
Using Named Functions Within Self-Executing Function Blocks In Javascript
Hi Ben, you forgot to mention the most important thing for named self-executing functions - they can be referenced by name ONLY inside their execution context (which is parens in this case), it mean ... read »
dee
Jun 18, 2013 at 7:01 AM
My Safari Browser SQLite Database Hello World Example
hai ben, this program is really good i could understand the concept but i dint know how to save it and how to open it as you have done in the video can u give that details pls ... read »
Jun 18, 2013 at 6:04 AM
Clearing Inline CSS Properties With jQuery
Thanks a lot for for post! It helped me a lot... after being stuck since 24 hrs.. found solution from your post. Thanks again! ... read »
Jun 18, 2013 at 2:31 AM
SOTR 2013 - The Best Conference I Never Went To
I keep watching it, should keep me happily distracted until SotR14 ;) ... read »
Jun 17, 2013 at 9:45 PM
What If All User Interface (UI) Data Came In Reports?
@Jonah, As I was reading what you wrote, it occurred to me that maybe I do something similar to that in some of my client-side code. In an application I'm working on, there are a bunch of unrelated ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools