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?

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.In PhixFlow version 11.1 onwards, this field is mandatory.

// 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
nopaneltrue
 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
nopaneltrue
 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.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

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's XML data structure in an Output Attribute:

XML DataExpressionReturns
XPath value_resultPF Title Text
XPath element attributes_result.namePF Title
XPath parent attributes

_result.^.page

PF Main Page
XPath child attributeslistToString(_result.datarow.data.initials)AA,BB
XPath child attribute text valueslistToString(_result.datarow.data)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, 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.

XML DataExpressionReturns
XPath element attributes

_result.h$name

PF Title
XPath child attributeslistToString(_result.h$datarow.h$data.h$initials)AA,BB
XPath child attribute text valueslistToString(_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
hiddentrue

Insert excerpt
XML Node
XML Node
nameWholePage
nopaneltrue

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

Create an RSS Feed using XML Data

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

Table Setup

  1. Create a new 
    Insert excerpt
    _tables
    _tables
    nopaneltrue
     on your 
    Insert excerpt
    _erd
    _erd
    nopaneltrue
     to save the 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
      2. Expression: _NULL
    6. 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 XML document
  4. Drag the 
    Insert excerpt
    _input
    _input
    nopaneltrue
     connection point node onto the
    Insert excerpt
    _http
    _http
    nopaneltrue
     action
  5. 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
  6. 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 PhixFlow to process
  7. Connect the out connector from the 
    Insert excerpt
    _http
    _http
    nopaneltrue
     to the
    Insert excerpt
    _action_xml
    _action_xml
    nopaneltrue
     action
    1. Map across the attribute, body

      Expand
      titleCheckpoint


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.title


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


      Code Block
      themeEmacs
      titleName: Link, Type: String
      _result.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


  2. Hover over the XML action and select out
  3. Create a
    Insert excerpt
    _action_save
    _action_save
    nopaneltrue
     action
    1. Primary Table: The News table you created earlier
    2. Map across the XML attributes to their relevant attributes on the Save action

      Expand
      titleHow?


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,
    Insert excerpt
    _lock
    _lock
    nopaneltrue
     the screen and click the 
    Start RSS Feed button
  2. If the Actionflow is working, the News grid should contain all of the BBC News data