Xquery Enhancements using XQSE

Well, I dont need to reiterate the usefulness of Xquery when it comes to OSB development. This is one of the few good XML technologies which i find amazing for XML processing and transformations but it is equally neglected as well. It needs to evolve as a programming language. As a matter of fact, I have found it lacking of so many things that are so critical sometimes.

During one of my transformation exercises I was supposed to handle date conversions in Xquery. The problem with using Xquery was that if any of the date formats comes wrong this would lead to an error in my Xquery and it will be aborted. However in my case what i needed to do was simply send a null/empty value in date field if the conversion failed for any reason. Miserable situation if we have only Xquery.

BEA came up with an extension for XQuery called XQSE (Read XQuery Scripting Extension) to use more programmatic blocks in Xquery. Here is an example

declare xqse function xf:CreateDateTimeFromString($DateTime as xs:string?)
as xs:dateTime? {

if(fn:string-length($DateTime)>8) then
return value  ( xs:dateTime(fn:concat (fn:substring($DateTime,1,4),’-‘,fn:substring($DateTime,5,2),’-‘, fn:substring($DateTime,7,2),’T’,
fn:substring($DateTime,9,2),’:’,fn:substring($DateTime,11,2),’:’,fn:substring($DateTime,13,2)))) ;

return value  (xs:dateTime(fn:concat(fn:substring($DateTime,1,4),’-‘,fn:substring($DateTime,5,2),’-‘, fn:substring($DateTime,7,2),’T’,’00:00:00′)));

}catch (* into $err, $msg) {
return value  () ;

The above xqse function allows us to surround our xquery with a try catch block. This is extremely useful for the case i explained above.

If you have any comments, suggestions or feedback about the post, please feel free to type it here and I will do my best to address them asap

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s