Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Insert excerpt | ||||||||
---|---|---|---|---|---|---|---|---|
|
What is an XML Action?
Image Modified
Insert excerpt | ||||||
---|---|---|---|---|---|---|
|
Creating XML Actions
- Click and drag the
icon from the toolbar onto the canvasInsert excerpt _action_xml _action_xml nopanel true - Enter a name for the XML action, then select Create Action
- In the XML action
on the right, populate the following details:Insert excerpt _property_settings _property_settings nopanel true
Field | Description | Example Value |
---|---|---|
Name | Name given to the XML Node. This will be displayed on the Actionflow canvas. | MyXMLReader |
Input Expression | This field is mandatory. 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 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 | ||||||
---|---|---|---|---|---|---|
|
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 | ||||||
---|---|---|---|---|---|---|
|
Image Modified
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. |
^ | 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
Expand | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||||||||||||||
XPath
ResultsThe following examples show how to reference the returned XPath's XML data structure in an Output Attribute:
Note the use of:
NamespacesXPathWithin 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. ResultsWithin attribute expressions, a $ is used instead of the normal : namespace notation.
The namespace prefix used here ' |
hidden | 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. |
Create an RSS Feed using XML Data
In this example, we'll create a table containing BBC News from an XML file.
Image Modified
Table Setup
- Create a new
on yourInsert excerpt _tables _tables nopanel true
to save the news data to, and ensure it contains the following attributes:Insert excerpt _erd _erd nopanel true - Name:
UID
- Type:
Integer
- Expression:
_NULL
- Type:
- Name:
Title
- Type:
String
- Expression:
_NULL
- Type:
- Name:
Description
- Type:
Bigstring
- Expression:
_NULL
- Type:
- Name:
Link
- Type:
String
- Expression:
_NULL
- Type:
- Name:
Date
- Type:
Datetime
- Expression:
_NULL
- Type:
- Name:
Source
- 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
action onto the canvas and give it a suitable name - this will be used to retrieve the news from the XML documentInsert excerpt _http _http nopanel true - Drag the
connection point node onto theInsert excerpt _input _input nopanel true
actionInsert excerpt _http _http nopanel true - Click on the
action to open its PropertiesInsert excerpt _http _http nopanel true - HTTP Method: GET
- URL: https://feeds.bbci.co.uk/news/technology/rss.xml
- Drag a
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 processInsert excerpt _action_xml _action_xml nopanel true - Connect the out connector from the
to theInsert excerpt _http _http nopanel true
actionInsert excerpt _action_xml _action_xml nopanel true Map across the attribute, body
Expand title Checkpoint Image Modified
XML Action Setup
- Click on the
action to open its Properties and populate the following:Insert excerpt _action_xml _action_xml nopanel true - 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
- Input Expression:
- Hover over the XML action and select out
- Create a
actionInsert excerpt _action_save _action_save nopanel true - Primary Table: The News table you created earlier
Map across the XML attributes to their relevant attributes on the Save action
Expand title How? Image Modified
Screen Setup
- Open the Shop News screen
- Click on
in the toolbar, then select the News table you created earlierInsert excerpt _attributes _attributes nopanel true - In the Available Attributes selector, select all attributes and drag them onto the screen, then choose to display the data as a
Insert excerpt _grid _grid nopanel true
Testing
- On the Shop News screen,
the screen and click the Start RSS Feed buttonInsert excerpt _lock _lock nopanel true - If the Actionflow is working, the News grid should contain all of the BBC News data
On this page
Table of Contents | ||
---|---|---|
|