Caution
Test the script(s), processes and/or data file(s) thoroughly in a test environment, and customize them to meet the requirements of your organization before attempting to use it in a production capacity.  (See the legal notice here)

 

Note: The workflow sample mentioned in this article can be downloaded from the Opalis project on CodePlex:  http://opalis.codeplex.com

 

Overview

This is a collection of Workflows that demonstrates how to parse and transform XML data using the Query XML and Apply XSLT Activities.

 

Query XML Example Workflows

Getting Started

Launch the Workflow named ‘0.Setup’ by using Start or by running it using the Testing Console. The Workflow will create a sample XML file named ‘authors.xml’ on the C: drive. This sample XML file will be used by the Query XML example Workflows. The XML file ‘authors.xml’ has following contents:

<?xml version="1.0" encoding="ISO-8859-1"?>
<authors>
    <author>
        <name>Mike Galos</name>
        <nationality>French</nationality>
    </author>
    <author period="modern">
        <name>Eva Corets</name>
        <nationality>English</nationality>
    </author>
    <author>
        <name>Cynthia Randall</name>
        <nationality>Canadian</nationality>
    </author>
    <author>
        <name>Stefan Knorr</name>
        <nationality>Canadian</nationality>
    </author>
    <author period="modern">
        <name>Paula Thurman</name>
        <nationality>English</nationality>
    </author>
</authors>

1. XPath Example

image

This Workflow extracts information from an XML file and sends Opalis Platform Events to display the results. The Query XML Activity ‘XPath Query’ extracts the names from the sample XML file by using an XPath query ‘//author/name’:

image

The Send Platform Event Activity displays the XML query result by subscribing to the appropriate Published Data from the ‘XPath Query’ Activity:

image

Running the example Workflow

Launch the Workflow ‘1. XPath Example’ by using Start, or by running it using the Testing Console. Check the Opalis Designer Events tab or the Testing Console log to see the resulting output:

image

 

2. XPath Example

image

This Workflow is similar to ‘1. XPath Example’ as it extracts information from an XML file and sends Opalis Platform Events to display the results. The Query XML Activity ‘XPath Query with Filter’ extracts the names for English authors from the sample XML file by using an XPath query ‘//author[nationality='English']/name’:

image

The Send Platform Event Activity displays the XML query result by subscribing to the appropriate Published Data from the ‘XPath Query with Filter’ Activity.

Running the example Workflow

Launch the Workflow ‘2. XPath Example’ by using Start, or by running it using the Testing Console. Check the Opalis Designer Events tab or the Testing Console log to see the resulting output:

image

 

3. XPath Example

image

This Workflow is the same as the Workflow named ‘1. XPath Example’, except that the ‘Run Behavior’ properties of the Query XML Activity ‘XPath Query (FLATTEN) is configured to flatten the multi-value Published Data and return a delimited string instead that uses ‘;’ as the separation character:

image

The Send Platform Event Activity displays the XML query result by subscribing to the appropriate Published Data from the ‘XPath Query with Filter’ Activity.

Running the example Workflow

Launch the Workflow ‘3. XPath Example’ by using Start, or by running it using the Testing Console. Check the Opalis Designer Events tab or the Testing Console log to see the resulting output:

image

image

 

Transform XML Example Workflow

Getting Started

Launch the Workflow named ‘0.Setup’ by using Start or by running it using the Testing Console.
The Workflow will create a sample XML file named ‘authors.xml’ on the C: drive. This sample XML file will be used by the Transform XML example Workflow. The XML file ‘authors.xml’ has following contents:

<?xml version="1.0" encoding="iso-8859-1"?>
<authors>
    <author>
        <name>Mike Galos</name>
        <nationality>French</nationality>
    </author>
    <author period="modern">
        <name>Eva Corets</name>
        <nationality>English</nationality>
    </author>
    <author>
        <name>Cynthia Randall</name>
        <nationality>Canadian</nationality>
    </author>
    <author>
        <name>Stefan Knorr</name>
        <nationality>Canadian</nationality>
    </author>
    <author period="modern">
        <name>Paula Thurman</name>
        <nationality>English</nationality>
    </author>
</authors>

The Workflow also creates a sample XSL file named ‘authors.xsl’ on the C drive. This sample XSL file will also be used by the Transform XML example Workflow. The XSL file ‘authors.xsl’ has following contents:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>
    <xsl:template match="/">
        <xsl:for-each select="//author">
            <xsl:value-of select="name"/>;<xsl:value-of select="nationality"/>&#10;
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

1. Transform XML to Text

image

This Workflow applies an XSL Tranformation to the sample XML file. The resulting text file is read and the contents displayed. The Apply XSLT is used to transform the XML data into a text file:

image

The Get Lines Activity reads all lines from the resulting text file ‘authors_transformed.txt’:

image

The Send Platform Event Activity displays the resulting output:

image

Running the example Workflow

Launch the Workflow ‘1. Transform XML to Text’ by using Start, or by running it using the Testing Console. Check the Opalis Designer Events tab or the Testing Console log to see the resulting output:

image

image

More Information

Refer to the Query XML and Transform XML Activity Online Help.

Share this post :