Posted 05/21/2010 - 00:44 by nzblue_fish
Hi mashers,
I've been a bit pre-occupied lately with other things and haven't had much time to write about my mashups, but I have been working on some useful things nonetheless.
I blogged a few weeks ago about using Wufoo to capture data via online forms and then grabbing the entered data using a mashup I had built to return the entries in an easily digestable form (via the Wufoo Query API).
I'd have to say that Wufoo is a wickedly easy way to build an online form, and combined with my mashup it's so easy to get the data back to use. We used it recently to quickly build a small application to capture some data and then present it in a smart little mashlet that used one or two of the cooler ExtJS classes.
Anyway, I digress, I am supposed to be blogging about What I Learnt Today. It's not a big thing, but one I've had to employ a few times in building more sophisticated mashup scripts in emml. This is probably for the beginners more than the experienced hands.
Is that node empty?
Today, I've been working on populating a SQL database table via a mashup script. Things were going smoothly until I tried to cast a null value as a Decimal before inserting a record into the SQL table. Most of the incoming records read via another service contained a numeric value, but one or two were being returned as an empty node. Trying to cast the contents of an empty node to a Decimal is going to give you a nice bunch of errors when the script executes. Best then to check before hand whether the node is empty and handle it appropriately.
You might think as I did that something like this:
<if condition="$sqlRecord/*:travel/text() eq ''">
would do the trick, pulling out the text node and then checking to see if it is equivalent to an empty string. As I discovered, that won't work (and I should have remembered that!).
What will work nicely, is checking to see if the node is empty with this form of the <if> statement that uses the XPath Empty function to see if the node really has nothing in it.
<if condition="empty($sqlRecord/*:travel/text())">
Now that worked much better.
Using this form, I could catch the empty nodes, then assign a zero value to the variable before casting it to the Decimal datatype that was expected in the SQL insert.
It's not a big lesson, but if you plan to build anything moderately complex in the way of emml script, I bet you'll be checking for empty nodes from time to time.
I hope this helps you beginners out there ...
Happy mashing folks,
Innes
- nzblue_fish's blog
- Login or register to post comments
- Email this page

Great tip! It's sometimes hard to find all the 'hidden gems' in XPath (the XPath spec being nowhere near 'easy reading' :-). And they absolutely do make life -- or mashup coding at least, easier.
<!--Session data-->
Sara, technical writer/jackbe