Wednesday 18 May 2016

Creating an array of XML element in BPEL

The objective of this post is to generate an XML response which has array of XML element using BPEL.

Problem Statement:

Input to the BPEL process : n / integer
Output from BPEL process : result / String array of length n

Solution:

To solve this problem, we can use <bpelx:append>  which is an BPEL extension function

namespace for bplex is xmlns:bpelx="http://schemas.oracle.com/bpel/extension"

Below is the code snippet where it inserts a node using bpelx:append

<bpel:assign name="InsertResponse">
  <bpelx:append>
    <bpelx:from>

        <result xmlns="http://xmlns.oracle.com/HelloWorlsApp/ArrayOutput/Collection">StringTest
        </result>
    </bpelx:from>
    <bpelx:to bpelx:language="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0" variable="outputVariable" part="payload" query="/client:processResponse"/>
   </bpelx:append>      
 </bpel:assign>


This assignment we can keep it inside a <bpel:while> with a condition like index should be less than the input n.


Sample Input

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
     <ns1:process xmlns:ns1="http://xmlns.oracle.com/HelloWorlsApp/ArrayOutput/Collection">
      <ns1:input>3</ns1:input>
       </ns1:process>
    </soap:Body>
</soap:Envelope>


Sample Output

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">
  <env:Body>
<processResponse xmlns="http://xmlns.oracle.com/HelloWorlsApp/ArrayOutput/Collection">
<result>StringTest</result>
<result>StringTest</result>
<result>StringTest</result>
</processResponse>
  </env:Body>
</env:Envelope>


Tuesday 3 May 2016

elementFormDefault attribute in XSD Schema definition

This attribute (elementFormDefault) is useful when we are defining our own <complexType> in our schema and the main purpose is to decide whether the <element> inside <complexType> should be in targetNamespace or global namespace

Example:
Sample XSD:
<?xml version = '1.0' encoding = 'UTF-8'?>
<xsd:schema xmlns:ns0="http://ticket.com/ns" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ticket.com/ns">  
   <xsd:complexType name="routeTicket">
      <xsd:sequence>
         <xsd:element name="ticket" type="xsd:string" minOccurs="0"/>
      </xsd:sequence>
   </xsd:complexType>
   <xsd:complexType name="routeTicketResponse">
      <xsd:sequence>
         <xsd:element name="return" type="xsd:string" minOccurs="0"/>
      </xsd:sequence>
   </xsd:complexType>
   <xsd:element name="routeTicket" type="ns0:routeTicket"/>
   <xsd:element name="routeTicketResponse" type="ns0:routeTicketResponse"/>

</xsd:schema>


when elementFormDefault="unqualified"
when elementFormDefault="qualified"
Valid XML for the given XSD:

<?xml version="1.0" encoding="utf-8"?>
<xs:routeTicket xmlns:xs="http://ticket.com/ns">
  <ticket>str1234</ticket>
</xs:routeTicket>

Valid XML for the given XSD:

<?xml version="1.0" encoding="utf-8"?>
<xs:routeTicket xmlns:xs="http://ticket.com/ns">
  <xs:ticket>str1234</xs:ticket>
</xs:routeTicket>

XPATH to access ticket

/xs:routeTicket/ticket

XPATH to access ticket

/xs:routeTicket/xs:ticket


Useful online tools