What is an XML Action?
Insert excerpt |
---|
| _action_xml |
---|
| _action_xml |
---|
nopanel | true |
---|
|
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
Insert excerpt |
---|
| _action_xml |
---|
| _action_xml |
---|
nopanel | true |
---|
|
icon from the toolbar onto the canvas - Enter a name for the XML action, then select Create Action
- In the XML action
Insert excerpt |
---|
| _property_settings |
---|
| _property_settings |
---|
nopanel | true |
---|
|
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 in.body
|
XPath | The XPath is used to navigate through elements and attributes in an XML document and determines which elements are extracted from the XML. 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 XPath returns the root element of the XML document, only one record will be returned. Whereas if the XPath returns children elements, one record will be returned for each child element. | // XML XPath /root/main/title
|
4.
Insert excerpt |
---|
| _finish |
---|
| _finish |
---|
nopanel | true |
---|
|
all settings
XPath Syntax
Expression | Description |
---|
/ | Traverses down into the XML structure. It is the child operator, used to denote a child element of the current element. All elements are delimited using this notation, e.g. /rss/Item/Date , will return the value held in the Date element. |
.. | Traverses up 1 element in the hierarchy from child to parent. |
[ ] | Selects a child element of the current element (by name or index number). |
@ | Selects all attributes with the specified name e.g. //@foo will return all attributes named foo in the XML document. See Attributes vs Elements for details. |
//
| Selects elements, from within the current element, that match the selection regardless of their location e.g. /root/item//bar will return all bar elements from within item. |
* | Is a wildcard, returning all elements regardless of their name. |
See XML and XPath and XPath Syntax for examples of how different XPath expressions provide different results.
Output Attributes
Add a list of attributes to be returned by the XML action, using the value _result.
followed by the Attribute Expression Syntax (see below) and the name of the element/attribute required. To add an Output Attribute, click the
Insert excerpt |
---|
| _addIcon |
---|
| _addIcon |
---|
nopanel | true |
---|
|
button and complete the appropriate details. For example:
Attribute Expression Syntax
Expression | Description |
---|
. | Traverses down into the XML structure. It is the child operator, used to denote a child element of the current element. All elements are delimited using this notation e.g. _result.Feed.TilteTtlte , will return the value held in Title element. |
^ | Traverses up 1 element in the hierarchy from child to parent. |
[ ] | Selects a child element of the current element (by name or index number). |
* | Is a wildcard, returning all elements regardless of their name. |
@ | Selects all attributes with the specified name, e.g. //@foo will return all attributes named foo in the XML document. |
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. Also, see Namespaces in the Example XML below.
Example XML
Code Block |
---|
|
<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> |
XPath
/root/main/title
Results
The following examples show how to reference the returned XPath's XML data structure in an Output Attribute:
XML Data | Expression | Returns |
---|
XPath value | _result | PF Title Text |
XPath element attributes | _result.name | PF Title |
XPath parent attributes | _result.^.page
| PF Main Page |
XPath child attributes | listToString(_result.datarow.data.initials) | AA,BB |
XPath child attribute text values | listToString(_result.datarow.data) | Alistair Andrews,Bert Brown |
Note the use of:
Namespaces
XPath
Within path expressions, namespaces are referred to using semicolons.
A record is created for each element returned by the path. Therefore, we do not recommend returning the root as this only returns a single record.
Results
Within attribute expressions, a $ is used instead of the normal : namespace notation.
XML Data | Expression | Returns |
---|
XPath element attributes | _result.h$name
| PF Title |
XPath child attributes | listToString(_result.h$datarow.h$data.h$initials) | AA,BB |
XPath child attribute text values | listToString(_result.h$datarow.h$data.value) | Alistair Andrews,Bert Brown |
The namespace prefix used here 'h
' must be configured in the XML Namespace.
HTML Comment |
---|
|
Insert excerpt |
---|
| XML Node |
---|
| XML Node |
---|
name | WholePage |
---|
nopanel | true |
---|
|
|
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
Tip |
---|
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. |
In this example, we'll create a table containing BBC News from an XML file.
Table Setup
- Create a new
Insert excerpt |
---|
| _tables |
---|
| _tables |
---|
nopanel | true |
---|
|
on your to save the news data to, and ensure it contains the following attributes:- Name:
UID
- Type:
Integer
- Expression:
_NULL
- Name:
Title
- Type:
String
- Expression:
_NULL
- Name:
Description
- Type:
Bigstring
- Expression:
_NULL
- Name:
Link
- Type:
String
- Expression:
_NULL
- Name:
Date
- Type:
Datetime
- Expression:
_NULL
- Name:
Source
- Type:
String
- Expression:
_NULL
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 action onto the canvas and give it a suitable name - this will be used to retrieve the news from the XML document
- Drag the connection point node onto the action
- Click on the action to open its Properties
- HTTP Method: GET
- URL: https://feeds.bbci.co.uk/news/technology/rss.xml
- Drag a
Insert excerpt |
---|
| _action_xml |
---|
| _action_xml |
---|
nopanel | true |
---|
|
action onto the canvas and give it a suitable name - this will be used to convert the XML data into data suitable for PhixFlow to process - Connect the out connector from the to the
Insert excerpt |
---|
| _action_xml |
---|
| _action_xml |
---|
nopanel | true |
---|
|
actionMap across all attributesthe attribute, body
Expand |
---|
|
|
XML Action Setup
- Click on the
Insert excerpt |
---|
| _action_xml |
---|
| _action_xml |
---|
nopanel | true |
---|
|
action to open its Properties and populate the following:- Input Expression:
in.body
- Path:
/rss/channel/item
Output Attributes:
Code Block |
---|
theme | Emacs |
---|
title | Name: Title, Type: String |
---|
|
_result.title |
Code Block |
---|
theme | Emacs |
---|
title | Name: Description, Type: Bigstring |
---|
|
_result.description |
Code Block |
---|
theme | Emacs |
---|
title | Name: Link, Type: String |
---|
|
_result.link |
Code Block |
---|
theme | Emacs |
---|
title | Name: ID, Type: String |
---|
|
_NULL |
Code Block |
---|
theme | Emacs |
---|
title | Name: Date, Type: Datetime |
---|
|
do(
$dater = replaceAll(_result.pubDate, " GMT", ""),
$dater = substring($dater, 6),
toDate($dater, "dd MMM yyyy HH:mm:ss")
) |
Code Block |
---|
theme | Emacs |
---|
title | Name: Source, Type: String |
---|
|
_result.^.title |
- Hover over the XML action and select out
- Create a
Insert excerpt |
---|
| _action_save |
---|
| _action_save |
---|
nopanel | true |
---|
|
action- Primary Table: The News table you created earlier
Map across the XML attributes to their relevant attributes on the Save action
Expand |
---|
|
|
Screen Setup
- Open the Shop News screen
- Click on
Insert excerpt |
---|
| _attributes |
---|
| _attributes |
---|
nopanel | true |
---|
|
in the toolbar, then select the News table you created earlier - In the Available Attributes selector, select all attributes and drag them onto the screen, then choose to display the data as a
Testing
- On the Shop News screen, the screen and click the Start RSS Feed button
- If the Actionflow is working, the News grid should contain all of the BBC News data
2.15 Analysis Action Configuration