Extract data from XML by Tag
  • 05 Jan 2024
  • 2 Minutes to read
  • Dark
    Light

Extract data from XML by Tag

  • Dark
    Light

Article Summary

Example Lab Article
While Example Lab projects are resources for public use, articles and assets are not actively maintained. Screenshots and features are from the specified version below. These references may become dated as new versions are released.


Overview

Example Lab Details

Version6.10.2
Root FolderXmlValue
Modules None
DependenciesNone

This example will show you how, from an XML file, you can extract data from a specific tag within a Flow.


Explanation

Create a new Flow and name it "Extract Text from XML Tag." On the Start Step, add two inputs; XML Tag as a string and XML as FileData.

Capture.PNG




In the steps catalog navigate to Data > Text and drag the "Get String From Bytes" Step onto the canvas and connect the Start Step to it. For the inputs, choose Select From Flow and choose "XML.Contents." This is a byte array that contains the XML data.

image.png




Next in the steps catalog under Data > Text, drag out the "Extract Text From Text" Step and connect "Get String From Bytes" to it. Cofigure the inputs as follows;

image.png




To ensure that what we have done is working, lets create a simple form to view the results. In the Steps Catalog, navigate to Forms [Interatcion] and drag "[Pick or Create Form]" onto the canvas and attach "Extract Text from Text" to it. Then create a new form by clicking on the new Form Step and choosing "Pick or Create Form" at the top left in the Properties panel. In the pop up name your Form "Show Form" and click Create. At the top add in a Text Area and Change the Data Name to "Block" and resize so you can view all of the XML. Then add a Text box below it so we can view the extracted data and change the Data Name to Block. Save and close the form. Back in the Flow Editor for inputs on the Form, Block will be "Seclect From Flow" and we will select "GetStringFromBytes_Output". For Out, choose "Seclect From Flow" and we will select "ExtractTextFromText1_Output".

image.png




Now we are ready to test our Flow. Choose Debug at the top, On the right you will need to choose, or drag, an XML file to be worked by the Flow. Under XML Tag, type in a tag that exists in your XML (Please Note: if the tag does not exist in your XML, this flow will fail) and click "Run Capturing All" at the bottom and view the results in the form.
image.png

image.png

Reference Articles
None

Project Download

The examples attached were developed to be instructional and were not developed as officially supported components. For more information or to engage our service team to develop fully supported, production quality solutions, please contact services@decisions.com. Import the project below to a Decisions environment on version 6.10.2 or later using our Importing/Exporting article.


Was this article helpful?