Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Thursday, 7 May 2015

Handling CDATA in BPM Web Service call

The most common problem that we face while invoking a web service which expects some xml as a string in CDATA from oracle BPM/BPEL.
Like 

"<![CDATA[<UnderwriterAssignment><ApplicationID>XXXXXXXX</ApplicationID><Underwriter>XXXX</Underwriter></UnderwriterAssignment>]]>"

The above string has to be passed to the webservice as a string.

The problem here is the engine will convert the < and > to &lt; and &gt; while invoking. But the service may not be coded in such a ways that it accepts like that and the web service invokation will fail.

To resolve this, 

  • Prepared (assign) the string that needs to be sent as CDATA.
  • someString = "<UnderwriterAssignment><ApplicationID>ATL620007</ApplicationID><Underwriter>satishs</Underwriter></UnderwriterAssignment>"
  • On the service call use ora:toCDATA() to convert it into proper CDATA without encoding
  • like ora:toCDATA(someString).
This will not encode the string and it will pass as it is.

Monday, 30 March 2015

Using for loop in XSL

By default xsl supports the for-each functionality which will iterate over the number of elements in source xml.
But what if we need something like for loop in normal programming language??
like for (int i=0;i<10 ;i++)

Solution:
We can achieve the above requirement with the help of callable template as described below,


 <xsl:template name="party">
    <xsl:param name="count"/>
    <xsl:param name="xml"/>

    <xsl:if test=" $count > 0">
            <name>
                  <xsl:value-of select="$xml/name"/>
          </name>
     </xsl:if>     
      <xsl:call-template name="party">
            <xsl:with-param name="count" select="$count - 1"/>
            <xsl:with-param name="xml" select="/"/>
        </xsl:call-template>  
  </xsl:template>          
       
   
Call the above template like this,

        <xsl:call-template name="party">
            <xsl:with-param name="count" select="6"/>
            <xsl:with-param name="xml" select="/"/>
        </xsl:call-template>           
                   
 
Above code creates the tag six times.

In this you can see how to access the source xml in the templates.
As you will not have direct access to the source xml in the callable template we need to pass it as parameter and use in the template.