Posts

Showing posts from September, 2020

XML to String and String to XML conversion

Use Cases Many a times, we may need to convert xml data and pass it as a string inside an XML tag. Sometimes from source, we get data which is in string format but actually is xml encoded in string format. To do so in Oracle BPEL 12c or OSB 12c we can use built in functions. XML data to String Sample input <inRoot>     <t1> Hello </t1>     <t2> World </t2>     <t3> One </t3> </inRoot> Sample output <outRoot>    <t1> &lt;inRoot&gt;&lt;t1&gt;Hello&lt;/t1&gt;&lt;t2&gt;World&lt;/t2&gt;&lt;t3&gt;One&lt;/t3&gt;&lt;/inRoot&gt; </t1> </outRoot> XSLT This can be accomplished by using the function  oraext:get-content-as-string(element as node-set) . This function is really helpful when we are working on BPEL as we can use this function in ASSIGN activity or in TRANSFORM activity using XSLT . xmlns:oraext ="http://www.oracle.com/XSL/Transform/java/oracle.tip

Remove Empty tags using XSLT

While performing xslt transform on source XML, we may need not to include empty tags in the output xml payload.  Sample scenarios:     1.  Target system doesn't want empty tags to come.      2. Size of xml payload has become huge due to unwanted empty tags. Source XML <inRoot>     <t1>Hello</t1>     <t2></t2>     <t3>World</t3> </inRoot> Output XML <outRoot>     <a1>Hello</a1>     <a3>World</a3> </outRoot> The optimal way to achieve above result is to use conditional if statement in xslt i.e. xsl:if Sample XSLT <xsl:if test = "/inRoot/t2!=''" >      <a2>           <xsl:value-of select = "ns0:C1" />      </a2> </xsl:if> If we have some whitespaces included between tags, the above if-statement may fail and in such scenarios, we may use normalize-space() function in xslt and test condition will become : "normalize-space(/inRoot/t2)!='&

Format String oraext:format-string

In our integration world, sometimes target system requires the data from source system to be formatted in some specific format which may require data from various input fields along with custom data. To do so we generally use concat()  function to concatenate data from various fields and some user specific inputs. Lets take the below example Suppose we have a predefined format for the output string: The abc with employeeID: 1234567 has been successfully registered in the system. Here, name of the employee( $empName ='abc') and employee id( $empId ='1234567') are dynamic values. One way to accomplish this, is to use concat(). concat('The ', $empName ,' with employeeID: ', $empId ,' has been successfully registered in the system.') Another way we can achieve this, is using  oraext:format-string (string,string,string...) oraext:format-string ('The {0} with employeeID: {1} has been successfully registered in the system.', $empName , $empId

DateTime formatting using xp20:format-dateTime ()

xs:dateTime Format In XML, we generally use xs:dateTime(xs:xmlns="http://www.w3.org/2001/XMLSchema") data type to store date time data. The generic representation of date time, that is supported by xs:dateTime in xml: YYYY-MM-DDThh:mm:ss[.SSS][Z|(+|-)hh:mm] Example :  2019-09-11T10:16:31.943+05:30 Code Description Example YYYY represents a 4-digit year 2019 MM represents a 2-digit month 09 DD represents 2-digit date 11 hh represents 2-digit hours 10 mm represents minutes in 2-digits 16 ss represents seconds in 2-digits 31 SSS represents milliseconds 943 T represents time separator T Z represents UTC time zone or 0 time zone offset (+|-)hh:mm represents time zone offset +5:30 Few more valid examples : 2019-09-11T21:32:52, 2019-09-11T21:32:52+02:

Popular posts from this blog

DateTime formatting using xp20:format-dateTime ()

Create Delimited String from XML Nodes and Vice Versa in SOA 12c

Import and Export MDS artifacts in SOA 12c