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

0

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 Author

Robert is a integration developer at heart and one of the expertise leads on Integration, Blockchain and IoT at AMIS. He is an respected author, speaker at (international) conferences and is a frequent blogger on the AMIS Technology blog, the Oracle Technology Network, and participates in OTN ArchBeat Podcasts. Robert is an member of the board of the Dutch Oracle User Group (nlOUG) and also organizes meetups.In 2017, Robert was named Oracle Developer Champion, but also hold the Oracle ACE title, for his contributions to the community. He is co-author of the first Oracle PaaS book published, which was published in January 2017. His fascination for technology had led to the research of Blockchain and is currently writing a book called Blockchain across Oracle.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.