Script to Parse XML in IBM BPM

We use XML parsing a lot during database calls. For retrieving data from a table it may return result of type “XMLElement”. In such cases we need to parse that in to an business object . Here I will show the same.

In my retrieve data integration service Im expecting result of type EmployeeDetails

Then in the Sql Excute nested service the return type is “XMLElement”

This above will return result of below type

This needs to be parsed as Business object to be sent as output

 

Parsing Script

if(tw.local.results != null && tw.local.results.childNodes && tw.local.results.childNodes.length > 0 ){
    var firstelement = tw.local.results.childNodes.item(0);
     tw.local.employeeData = new tw.object.EmployeeDetails();
     tw.local.employeeData.employeeId = firstelement.xpath("record/column[@name='EMPID']")[0].getText();
     tw.local.employeeData.name = firstelement.xpath("record/column[@name='EMPLOYEENAME']")[0].getText();
     tw.local.employeeData.place = firstelement.xpath("record/column[@name='PLACE']")[0].getText();
     tw.local.employeeData.phone = firstelement.xpath("record/column[@name='PHONE']")[0].getText();
     tw.local.employeeData.designation = firstelement.xpath("record/column[@name='DESIGNATION']")[0].getText();
     tw.local.employeeData.department = firstelement.xpath("record/column[@name='DEPARTMENT']")[0].getText();
     tw.local.employeeData.qualification = firstelement.xpath("record/column[@name='QUALIFICATION']")[0].getText();
     tw.local.employeeData.address = firstelement.xpath("record/column[@name='ADDRESS']")[0].getText();
}

This results in below output variable

 Same way we can parse for other return types such as NameValuePair etc.

Please do comment if you have any questions . Hope this helps someone and have a good day!
Advertisements

One thought on “Script to Parse XML in IBM BPM

  1. Pingback: Inserting and Retrieving records in to database(sql) using IBM BPM – harishvarma

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s