What is an XML Action?
XML actions process XML data, and convert it into specific data objects that can be used by PhixFlow for processing. The XML action extracts one or more records from the provided XML document using the XPath specified.
Creating XML Actions
- Click and drag the XML icon from the toolbar onto the canvas
- Enter a name for the XML action, then select Create Action
- In the XML action Properties on the right, populate the following details:
Field | Description | Example Value |
---|---|---|
Name | Name given to the XML Node. This will be displayed on the Actionflow canvas. | MyXMLReader |
Input Expression | The input expression provides the source of the XML data to be operated upon. Typically, this will be a simple expression pointing at an incoming attribute, such as, the body from a HTTP Node. | // Consists of the pipe name and the name of a mapped attribute
|
XPath | The XPath expression is evaluated against the XML document provided by the Input Expression and returns a list of XML elements. It determines which elements are extracted from the XML. Note that the XPath determines the number of elements that are processed, which directly correlates to the number of records returned by the XML Node. For example, if the path returns the route element of the XML Document, only one record will be returned. Whereas a path that returns children nodes will return one record for each child element. | // XML XPath /root/main/title |
4. Apply and Close all settings
XPath Syntax
Expression | Description |
---|---|
| symbol refers to the root element. |
@ | symbol refers to the current element. |
. | is the dot-child operator, which is used to denote a child element of the current element. |
[ ] | is used to select a child element of the current element (by name or index number). |
* | a wildcard, returning all elements regardless of their name. |
^ | symbol is used to traverse up 1 element in the hierarchy from child to parent. |
What about / ?
Output Attributes
Add a list of attributes to be returned by the XML action, using the syntax _result.
AttributeName
. To add an Output Attribute, click the button and complete the appropriate details. For example:
XML Namespaces
XML Namespaces provide a method to avoid element name conflicts by ensuring they are unique.
XML documents containing namespaces are supported.
For more information on XML Namespaces, see https://www.w3schools.com/xml/xml_namespaces.asp and XML Namespace.
Example XML
<root xmlns:h="http://example.com/schema"> <main page="PF Main Page"> <h:title name="PF Title">PF Title Text"> <h:datarow> <h:data h:initials="AA">Alistair Andrews<data> <h:data h:initials="BB">Bert Brown</data> </h:datarow> </h:title> </main> </root>
/root/main/title
The following examples show how to reference the returned xPath's xml data structure in an Output Attribute:
- Xpath value: _result → returns 'PF Title Text'
- Xpath element attributes: _result.name → returns 'PF Title'
- Xpath parent attributes: _result.^.page -> returns 'PF Main Page'
- Xpath child attributes: listToString(_result.datarow.data.initials) → returns 'AA,BB'
- Xpath child attribute text values: listToString(_result.datarow.data) → returns 'Alistair Andrews,Bert Brown'
Note the use of:
^
to traverse to the immediate parent element.- . to traverse to the immediate child element.
the
listToString
function to handle multiple matching child elements/attributes.
Namespaces
Within path expressions, they are referred to using semicolons.
- /root/main/h:title
Within attribute expressions, a $ is used instead of the normal : namespace notation.
- Xpath element attibutes: _result.h$name → returns 'PF Title'
- Xpath child attributes: listToString(_result.h$datarow.h$data.h$initials) → returns 'AA,BB'
- Xpath child attribute text values: listToString(_result.h$datarow.h$data.value) -> returns 'Alistair Andrews,Bert Brown'
The namespace prefix used here 'h
' must be configured in the XML Namespace.
Worked Example
Here is a worked example using an XML file from BBC News (https://feeds.bbci.co.uk/news/technology/rss.xml).
In this example, we are using:
- A Shop News screen containing a blank grid and a button - this screen was created using the Multi-tile template
If you are completing this chapter as part of the Actionflow course and using a training instance, the data and screens have already been pre-loaded into the Actionflow Intermediate Application. For these example, we'll be working on the Shop News screen.
GIF/SCREENSHOT OF FINISHED RESULT
Create a RRS Feed using XML Data
In this example, we'll create a table containing BBC News from an XML file.
Table Setup
- Create a new Table on your ERD to save the BBC news data to, and ensure it contains the following attributes:
- Name:
UID
- Type:
Integer
- Expression:
_NULL
- Type:
- Name:
Title
- Type:
String
- Expression:
_NULL
- Type:
- Name:
Description
- Type: Bigstring
- Expression:
_NULL
- Name:
Link
- Type:
String
- Expression:
_NULL
- Type:
- Name:
Actionflow Setup
- On the Shop News screen, add an Actionflow on the Start RSS Feed button
- Select Click to Connect and choose On Click
- Drag a HTTP action onto the canvas and give it a suitable name - this will be used to retrieve the news from the BBC XML
- Drag the input connection point node onto the HTTP action
- Click on the HTTP action to open its Properties
- HTTP Method: GET
- URL: https://feeds.bbci.co.uk/news/technology/rss.xml
- Log Traffic:
- Drag a XML action onto the canvas and give it a suitable name - this will be used to convert the XML data into data suitable for our BBC News table
- Connect the out connector from the HTTP node to the XML node
- Click on the connector between the HTTP action and the XML action
- Map across all attributes
XML Action Setup
- Click on the XML action to open its Properties
- Input Expression:
in.body
- Path:
/rss
Output Attributes:
Name: Title, Type: String_result.channel.title
Name: Description, Type: Bigstring_result.channel.description
Name: Link, Type: String_result.channel.link
Name: ID, Type: String_NULL
- Input Expression:
- Hover over the XML action and select out
- Create a Save action
- Primary Table:
BBC_News
- Primary Table:
Save Action and Open Screen Action Setup
- Click on the connector between the XML action and the Save action
Map across the XML attributes to their relevant attributes on the Save action
Testing
- On the Shop News screen, lock the screen and click the Start RSS Feed button
- If the Actionflow is working, the BBC News grid should contain all of the BBC News data