Insert excerpt | ||||||||
---|---|---|---|---|---|---|---|---|
|
What is an XML Action?
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 | 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.
Insert excerpt | ||||||
---|---|---|---|---|---|---|
|
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
Contains Add a list of attributes to be returned by the node. In this node XML is converted into data objects that can be used by PhixFlow, this information is accessed XML action, using the syntax _result.
AttributeName
in an output attribute. To add an output attribute Output Attribute, click the
Insert excerpt | ||||||
---|---|---|---|---|---|---|
|
XML Namespaces
XML Namespaces provide a method to avoid element name conflicts by ensuring they are unique.
The grid contains a list of the namespaces defined in an XML responseXML 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
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> |
/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.
HTML Comment | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
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. |
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
on yourInsert excerpt _tables _tables nopanel true
to save the BBC 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
- 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
action onto the canvas and give it a suitable name - this will be used to retrieve the news from the BBC XMLInsert 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
- Log Traffic:
Insert excerpt _toggle_off _toggle_off nopanel true
- 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 our BBC News tableInsert excerpt _action_xml _action_xml nopanel true - Connect the out connector from the HTTP node to the XML node
- Click on the connector between the
action and theInsert excerpt _http _http nopanel true
actionInsert excerpt _action_xml _action_xml nopanel true - Map across all attributes
XML Action Setup
- Click on the
action to open its PropertiesInsert excerpt _action_xml _action_xml nopanel true - Input Expression:
in.body
- Path:
/rss
Output Attributes:
Code Block theme Emacs title Name: Title, Type: String _result.channel.title
Code Block theme Emacs title Name: Description, Type: Bigstring _result.channel.description
Code Block theme Emacs title Name: Link, Type: String _result.channel.link
Code Block theme Emacs title Name: ID, Type: String _NULL
- Input Expression:
- Hover over the XML action and select out
- Create a
actionInsert excerpt _action_save _action_save nopanel true - 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
Expand title How?
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