1
Write a post

How to Parse BPEL(Business Process Execution Language)Files Using Python

Published Apr 08, 2017

What is BPEL ?

BPEL (Business Process Execution Language) is an XML-based language that allows Web services in a service-oriented architecture (SOA) to interconnect and share data.
Programmers use BPEL to define how a business process that involves web services will be executed. BPEL messages are typically used to invoke remote services, orchestrate process execution and manage events and exceptions.

For more details about bpel : Click-Here

What is Parsing ?

Parsing is extracting data in such a way so that we can make sense out of extracted data.

How to Parse BPEL File Using Python ?

For Parsing BPEL File,We will use Element-Tree XML API.This is sample source code which we will parse in next step.

Test.bpel

<?xml version="1.0" encoding="utf-8"?> 

<!-- Employee -->

<process name="Employee" 
         targetNamespace="http://packtpub.com/service/employee/" 
         xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
         xmlns:emp="http://packtpub.com/service/employee/" >
   
   <partnerLinks>
      <partnerLink name="employeeTravelStatus" 
                   partnerLinkType="emp:employeeLT"
                   myRole="employeeTravelStatusService"/>

   </partnerLinks>

   <variables>
      <!-- input for this process -->      
      <variable name="EmployeeTravelStatusRequest" messageType="emp:EmployeeTravelStatusRequestMessage"/>
      <!-- output from the Employee Travel Status web service -->
      <variable name="EmployeeTravelStatusResponse" messageType="emp:EmployeeTravelStatusResponseMessage"/>
   </variables>

   <sequence>

      <!-- Receive the initial request for business travel from client -->
      <receive partnerLink="employeeTravelStatus" 
               portType="emp:EmployeeTravelStatusPT" 
               operation="EmployeeTravelStatus" 
               variable="EmployeeTravelStatusRequest"
               createInstance="yes" />

      <!-- Prepare the output -->
      <assign>
        <copy>
          <from>
            <travelClass xmlns="http://packtpub.com/service/employee/">Economy</travelClass>
          </from>
          <to variable="EmployeeTravelStatusResponse" part="travelClass"/>
        </copy>
      </assign>
      
      <!-- Send a response -->
      <reply partnerLink="employeeTravelStatus" 
             portType="emp:EmployeeTravelStatusPT" 
             operation="EmployeeTravelStatus" 
             variable="EmployeeTravelStatusResponse"/>
   </sequence>

</process>

Using Element-Tree Api,we will extract all the tags with namespace.

Parser.py

import xml.etree.ElementTree as ET

class Parsing():

  def __init__(self):
    pass
  def depthSearch(self,root):
    if root is None:
      return
    else:
      print(root.tag)
      for child in root:
        print(child.tag)
        self.depthSearch(child)
    return

  def bpelparsing(self,filename):
    tree = ET.parse(filename)
    root = tree.getroot()
    self.depthSearch(root)
    

if __name__ == "__main__":
  parse_ref = Parsing()
  parse_ref.bpelparsing("Test.bpel")
  pass

How to Test ?

Python Version : 3.X

Run : Python Parser.py

Output :
All tags with namespace...

output.png

If we want to extract more information about a particular tag then use other option like
for extracting tag attributes use child.attrib.

This is an overview,How we can make use of element-tree api.For more details related to calculating bpel-bookmark etc.

Discover and read more posts from Arpit
get started
Enjoy this post?

Leave a like and comment for Arpit

Be the first to share your opinion

Get curated posts in your inbox

Learn programming by reading more posts like this