- 05 Jan 2024
- 2 Minutes to read
- Print
- DarkLight
Extract data from XML by Tag
- Updated on 05 Jan 2024
- 2 Minutes to read
- Print
- DarkLight
Overview
Example Lab Details | |
Version | 6.10.2 |
Root Folder | XmlValue |
Modules | None |
Dependencies | None |
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.
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.
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;
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".
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.