How to read an XML file

In this post, you’ll learn how to read an XML file with the integrated FileConnector:

  • Create a sample demo XML file
  • Create a FileConnector Service Group and Service Container
  • Create a new Workspace and Project + add the relevant folder structure
  • Add the FileConnector runtime reference Method Set
  • Create a BPMN based process (= structure process) to read the file

Demo XML file

Create a sample XML file:

Sample XML file Person
<person>
   <firstname>John</firstname>
   <lastname>Smith</lastname>
   <address>
      <street>Milton Road</street>
      <housenumber>10</housenumber>
      <city>London</city>
   </address>
</person>

Store the file here: C:\demo\person.xml

Store the XML file

FileConnector Service Group and Container

Open the System Resource Manager and create a new Service Group and Service Connector:

Select FileConnector as Application Connector and click Next:

FileConnector as Application Connector

Provide the name, description, select all Web Service Interfaces and click the Next button:

Service Group details

Provide the Service Container details and click Next:

Service Container details

Leave all information as they are and click Next:

FileConnector properties

Leave all information as they are and click Finish:

Connection Point

Start the FileConnector Service Container:

FileConnector Service Group – running

Create a Workspace and add the runtime reference

Create a new Workspace/Project and add the FielConnector Method Set from the runtime references. Your project might look like this:

Workspace, Project for the demo

Runtime references can be added like this: right click on the folder that should contain the references, click on add runtime references and in our case select the Web Service Interface. Then select the FileConnector Method Set:

Method Set FileConnector (Method Set FileConnector)

To test the added runtime reference, right click on ReadXMLFileRecords service and provide following SOAP request data:

<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP:Body>
    <ReadXmlFileRecords xmlns="http://schemas.cordys.com/1.0/ac/FileConnector">
      <filename>C:\demo\person.xml</filename>
      <selectPath>*</selectPath>
      <numrecords>1</numrecords>
      <offset>0</offset>
      <validateonly>false</validateonly>
      <returnAsText>false</returnAsText>
      <usetupleold>false</usetupleold>
    </ReadXmlFileRecords>
  </SOAP:Body>
</SOAP:Envelope>
SOAP request

Click Invoke and have a look at the SOAP response:

SOAP response

Create a process

Create a Business Process Model, assign the ReadXMLFileRecords to the first task and save the model (e.g. as FileConnectorDemoProcess):

Initial process model

Open the Message Map and provide as input data for the service the data you just used for the service test tool (use Replace Content With Fixed Value as assignment type):

Input message

Select the other task, create a new Process Specific Message called PersonMsg and add two elements:

  • Firstname and
  • City.

Add following Pre Assignments:

Pre Assignments

For Firstname:

  • Assignment type: Replace Content With Expression
  • Expression (use your namespace!): ns2:ReadXmlFileRecordsOutput/ns2:ReadXmlFileRecordsResponse/ns2:data/ns2:person/ns2:firstname/text()

For City:

  • Assignment type: Replace Content With Expression
  • Expression (use your namespace!): ns2:ReadXmlFileRecordsOutput/ns2:ReadXmlFileRecordsResponse/ns2:data/ns2:person/ns2:address/ns2:city/text()

Run your process and verify that Firstname and City a refilled correctly.

Remarks

  • Normally, you’d use the GetListOfFiles service to receive a list of all files within a folder and maybe filter only the files that you’d like to read. Then you’d iterate using a while/for loop and then read the content of the files in a sub process using the file name list as variables for the ReadXMLFileRecords service
  • You can also create an XML schema and use it within the Message Map for the assignments.

Leave a Reply

Your email address will not be published. Required fields are marked *