Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Insert excerpt
_Banners
_Banners
nameactionflow
nopaneltrue

What is an XML Action?

Image Modified

Insert excerpt
_action_xml
_action_xml
nopaneltrue
 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

  1. Click and drag the 
    Insert excerpt
    _action_xml
    _action_xml
    nopaneltrue
     icon from the toolbar onto the canvas
  2. Enter a name for the XML action, then select Create Action
  3. In the XML action 
    Insert excerpt
    _property_settings
    _property_settings
    nopaneltrue
     on the right, populate the following details:
FieldDescriptionExample Value
NameName 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

in.body

XPath

The XPath

expression is evaluated against the XML document provided by the Input Expression and returns a list of XML elements. It

is used to navigate through elements and attributes in an XML document and determines which elements are extracted from the XML.

Note that the

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

XPath returns the

route

root element of the XML

Document

document, only one record will be returned. Whereas

a path that

if the XPath returns children

nodes will return

elements, one record will be returned for each child element.

// XML XPath

/root/main/title

4. 

Insert excerpt
_finish
_finish
nopaneltrue
 all settings

XPath Syntax

Expression Description
$
/ 
symbol refers to the root element.@symbol refers to the current element.. is the dot-
Traverses down into the XML structure. It is the child operator,
which is
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. 
[ ] 
is used to select What about / ?
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.
^symbol is used to traverse up 1 element in the hierarchy from child to parent. 

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

syntax 

value _result.

AttributeName

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
nopaneltrue
 button and complete the appropriate details. For example:

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. _result.Feed.Ttlte, 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

Expand
titleSee Example


Code Block
languagexml
<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

XPath's

xml

XML data structure in an Output Attribute:

Xpath value: _result → returns '
XML DataExpressionReturns
XPath value_resultPF Title Text
'
Xpath
XPath element attributes
 → returns '
PF Title
'
Xpath
XPath parent attributes
: 

_result.^.page

 -> returns '

PF Main Page
'
Xpath
XPath child attributes
: 
listToString(_result.datarow.data.initials)
 → returns '
AA,BB
'
Xpath
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

XPath

Within path expressions,

they

namespaces are referred to using semicolons. 

  • /root/main/h:title

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.

Xpath element attibutes: 

XML DataExpressionReturns
XPath element attributes

_result.h$name

 → returns '

PF Title
'
Xpath
XPath child attributes
: 
listToString(_result.h$datarow.h$data.h$initials)
 → returns '
AA,BB
'
Xpath
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 Insert excerptXML NodeXML NodenameWholePagenopaneltrue

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:  

  • 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


Excerpt
nameXMLActionExample

Create an RSS Feed using XML Data

In this example, we'll create a table containing BBC News from an XML file.

Image Added

Table Setup

  1. Create a new 
    Insert excerpt
    _tables
    _tables
    nopaneltrue
     on your 
    Insert excerpt
    _erd
    _erd
    nopaneltrue
     to save the
BBC
  1. news data to, and ensure it contains the following attributes:
    1. Name: UID
      1. Type: Integer
      2. Expression: _NULL
    2. Name: Title
      1. Type: String
      2. Expression: _NULL
    3. Name: Description
      1. Type: Bigstring
      2. Expression: _NULL
    4. Name: Link
      1. Type: String
      2. Expression: _NULL
    5. Name: Date
      1. Type: Datetime
Actionflow Setup
      1. Expression: _NULL
    1. Name: Source
      1. Type: String
      2. Expression: _NULL

Actionflow Setup 

  1. On the Shop News screen, add an Actionflow on the Start RSS Feed button
  2. Select Click to Connect and choose On Click
  3. Drag a 
    Insert excerpt
    _http
    _http
    nopaneltrue
     action onto the canvas and give it a suitable name - this will be used to retrieve the news from the
BBC
  1. XML document
  2. Drag the 
    Insert excerpt
    _input
    _input
    nopaneltrue
     connection point node onto the
    Insert excerpt
    _http
    _http
    nopaneltrue
     action
  3. Click on the 
    Insert excerpt
    _http
    _http
    nopaneltrue
     action to open its Properties
    1. HTTP Method: GET
    2. URL: https://feeds.bbci.co.uk/news/technology/rss.xml
Log Traffic:  Insert excerpt_toggle_off_toggle_offnopaneltrue
  1. Drag a 
    Insert excerpt
    _action_xml
    _action_xml
    nopaneltrue
     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
  1. PhixFlow to process
  2. Connect the out connector from
the HTTP node to
  1. the
XML nodeClick on the connector between the
  1.  
    Insert excerpt
    _http
    _http
    nopaneltrue
 action and
  1.  to the
    Insert excerpt
    _action_xml
    _action_xml
    nopaneltrue
     action
    1. Map across

all attributes
    1. the attribute, body

      Expand
      titleCheckpoint

      Image Added


XML Action Setup

  1. Click on the 
    Insert excerpt
    _action_xml
    _action_xml
    nopaneltrue
     action to open its Properties and populate the following:
    1. Input Expression: in.body
    2. Path: /rss/channel/item
    3. Output Attributes:

      Code Block
      themeEmacs
      titleName: Title, Type: String
      _result
.channel
    1. .title


      Code Block
      themeEmacs
      titleName: Description, Type: Bigstring
      _result
.channel
    1. .description


      Code Block
      themeEmacs
      titleName: Link, Type: String
      _result
.channel
    1. .link


      Code Block
      themeEmacs
      titleName: ID, Type: String
      _NULL


      Code Block
      themeEmacs
      titleName: Date, Type: Datetime
      do(
      	$dater = replaceAll(_result.pubDate, " GMT", ""),
      	$dater = substring($dater, 6),
      	
      	toDate($dater, "dd MMM yyyy HH:mm:ss")
      )


      Code Block
      themeEmacs
      titleName: Source, Type: String
      _result.^.title


  1. Hover over the XML action and select out
  2. Create a
    Insert excerpt
    _action_save
    _action_save
    nopaneltrue
     action
    1. Primary Table:
BBC_News

Save Action and Open Screen Action Setup

Click on the connector between the XML action and the Save action
    1.  The News table you created earlier
    2. Map across the XML attributes to their relevant attributes on the Save action

      Expand
      titleHow?
Image Removed
    1. Image Added


Screen Setup

  1. Open the Shop News screen
  2. Click on 
    Insert excerpt
    _attributes
    _attributes
    nopaneltrue
     in the toolbar, then select the News table you created earlier
  3. 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
    nopaneltrue

Testing

  1. On the Shop News screen,
lock the
  1. Insert excerpt
    _lock
    _lock
    nopaneltrue
     the screen and click the 
    Start RSS Feed button
  2. If the Actionflow is working, the 
BBC
  1. News grid should contain all of the BBC News data
1.02 Actionflow Principles