SOA Top Tips #1 – Using a common XQuery Function Library

Robert van Molken
0 0
Read Time:2 Minute, 12 Second

In this series I will tell you about my favorite tips I give to colleagues and other integration developers during my daily work.
My first tip is about the usage of a common XQuery Function Library.

During my daily work I come across easy transformations, but some can get quite complex. In XQuery for instance you have a lot of power in your hands by using complex FLOWR expressions, but usually the most common mappings include checking an element for existence and performing an if/else construction.

{
  if ($aisOutputVariable.OutputParameters/haa:P_AIS_OUTPUT/haa:MESSAGE_NUMBER)
  then 
    
      {fn:data($aisOutputVariable.OutputParameters/haa:P_AIS_OUTPUT/haa:MESSAGE_NUMBER)}
    
  else ()
}

 
In my current project we use SOA Suite 12c and XQuery for mappings. A typical SOA Composite consist of a select on database tables using PL/SQL package/procedure and returning the data in PL/SQL types with a layered construction. When we produce an instance of the return type in the PL/SQL the data is inserted into the type. When a column is nillable and has a NULL value the field within the type is still instantiated and the field is returned by the database adapter, but it is empty / without a value. We ran into problems with our mappings because we checked if the element existed, instead of checking the actual content of the field, and mappings were not valid when validating based on the XSD, because some values of elements did not contain the right datatype/format.

Because this needed to be done in more than just one transformation we decided to invest in creating common XQuery functions. For example checking the values like zero-string length and non-valid integers.

declare function all-whitespace
  ( $arg as xs:string? )  as xs:boolean {

    normalize-space($arg) = ''
  } ;
declare function is-a-number
  ( $value as xs:anyAtomicType? )  as xs:boolean {

    string(number($value)) != 'NaN'
  } ;

 
But before you invest in creating your own library take a look into the library made by xqueryfunctions.com (FunctX). It contains a lot of function that can help you in your daily work. Just put the library, which you can download here, into a shared repository like the MDS and import it as a library into your existing XQuery transformation.

Import as XQuery Library

The FunctX library consists of 151 extra functions besides the 111 built-in XQuery functions. These functions are sorted in 10 different catagories like Strings, Numbers, Atomic Values of All Types, Sequences, XML Elements & Attributes and even a category for XML Namespaces. The most functions I use are for checking missing values, Trimming and Padding and Constructing and Converting dates.

About Post Author

Robert van Molken

Robert designs and develops application integration solutions both on-premises and in the cloud. Traditionally the solutions where based on the Oracle Middleware Stack, but lately he advises solutions that use a more cloud-native or hybrid approach. Besides application integration development he is an advocate on Blockchain, IoT and Microservices. Robert is heavily involved in the developer community.He is an international speaker at conferences (CodeOne, TeqNation, Open World), author of two books, blogger, and participates in tech related Podcasts. For this effort Robert was awarded Oracle ACE Associate in 2015, Oracle ACE in 2016, and Developer Champion in 2017 (which was renewed from 2018 to Oracle Groundbreaker Ambassador).
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %
Next Post

Book Review: Design Principles for Process-driven Architectures Using Oracle BPM and SOA Suite 12c (Packt, June 2015)

I recently came across an unexpected gem: this book titled “Design Principles for Process-driven Architectures Using Oracle BPM and SOA Suite 12c” by a collective of authors I know well and happily collaborate with: Torsten Winterberg, Mark Simpson, Guido Schmutz, Danilo Schmiedel, Hajo Normann, Sven Bernhardt, Matjaz B. Juric. The […]
%d bloggers like this: