Thursday, April 7, 2022

OIC - Convert String XML to XML using parseXML() | Use of ParseXML() function

Usecase: we will receive string xml data from source and then convert it back to XML content using parseXML() function and Rest API.

Highlevel steps: 

  • Using rest connection, configure app driven orchestration integration request and response.
    • In request & response, we will use XML schema as  payload format.
  • In the map, we will take parseXML() function which takes string XML as argument and map to execute response.
  • In the map code, change the value-of element name to copy-of. If you use only value-of then we will get only the parsed xml values ,not the element names. TO get values with element names, we have to use copy-of element.

Request XML for Rest API:
<?xml version="1.0" encoding="utf-8"?>
<Input xmlns="http://org.poc.com/v1.0">
<XMLString>abcd</XMLString>
</Input>

Response schema for Rest API:
<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.poc.org" xmlns:ns0="http://www.poc.org" targetNamespace="http://www.poc.org"
            elementFormDefault="qualified">
  <xsd:element name="Employees">   
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="Employee" type="EmployeeType" minOccurs="0" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
    <xsd:complexType name="EmployeeType">
      <xsd:sequence>
        <xsd:element name="EMPLOYEE_ID" type="xsd:string"/>
        <xsd:element name="FIRST_NAME" type="xsd:string"/>
<xsd:element name="LAST_NAME" type="xsd:string"/>
<xsd:element name="AGE" type="xsd:string"/>
<xsd:element name="DEPARTMENT_NAME" type="xsd:string"/>
<xsd:element name="DEPARTMENT_ID" type="xsd:string"/>
<xsd:element name="COUNTRY" type="xsd:string"/>
<xsd:element name="SALARY" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
</xsd:schema>

XML data:
<?xml version="1.0" encoding="utf-8"?>
<Employees>
  <Employee>
    <EMPLOYEE_ID>str1234</EMPLOYEE_ID>
    <FIRST_NAME>str1234</FIRST_NAME>
    <LAST_NAME>str1234</LAST_NAME>
    <AGE>str1234</AGE>
    <DEPARTMENT_NAME>str1234</DEPARTMENT_NAME>
    <DEPARTMENT_ID>str1234</DEPARTMENT_ID>
    <COUNTRY>str1234</COUNTRY>
    <SALARY>str1234</SALARY>
  </Employee>
</Employees>

String XML data to be tested:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;Employees&gt;
  &lt;Employee&gt;
    &lt;EMPLOYEE_ID&gt;str1234&lt;/EMPLOYEE_ID&gt;
    &lt;FIRST_NAME&gt;str1234&lt;/FIRST_NAME&gt;
    &lt;LAST_NAME&gt;str1234&lt;/LAST_NAME&gt;
    &lt;AGE&gt;str1234&lt;/AGE&gt;
    &lt;DEPARTMENT_NAME&gt;str1234&lt;/DEPARTMENT_NAME&gt;
    &lt;DEPARTMENT_ID&gt;str1234&lt;/DEPARTMENT_ID&gt;
    &lt;COUNTRY&gt;str1234&lt;/COUNTRY&gt;
    &lt;SALARY&gt;str1234&lt;/SALARY&gt;
  &lt;/Employee&gt;
&lt;/Employees&gt;

Detailed steps:

Integration flow:


Take rest trigger and configure post with request and response.





Map the requeest to response using parseXML().



In the map code, change value-of with copy-of elelment name.



Add tracking, save, activate and test.



No comments:

Post a Comment

Featured Post

OIC - Source File Validation Using Stage File and Throw New Fault in OIC

Working... Source File Validation Using Stage File and Throw New Fault in OIC Use Case In Oracle Integration Cloud (OIC), validating the s...