Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

What is an XML Action?

 XML 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  XML icon from the toolbar onto the canvas
  2. Enter a name for the XML action, then select Create Action
  3. In the XML action  Properties 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

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 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.  Apply and Close all settings

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

Add a list of attributes to be returned by the XML action, using the syntax _result.AttributeName. To add an Output Attribute, click the  button and complete the appropriate details. For example:

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.

Example XML

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

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

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

  1. Create a new  Table on your  ERD to save the BBC 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

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  HTTP action onto the canvas and give it a suitable name - this will be used to retrieve the news from the BBC XML
  4. Drag the  input connection point node onto the HTTP action
  5. Click on the  HTTP action to open its Properties
    1. HTTP Method: GET
    2. URL: https://feeds.bbci.co.uk/news/technology/rss.xml
    3. Log Traffic: 
  6. Drag a  XML 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
  7. Connect the out connector from the HTTP node to the XML node
  8. Click on the connector between the  HTTP action and the XML action
    1. Map across all attributes

XML Action Setup

  1. Click on the  XML action to open its Properties
    1. Input Expression: in.body
    2. Path: /rss
    3. Output Attributes:

      Name: Title, Type: String
      _result.channel.title


      Name: Description, Type: Bigstring
      _result.channel.description
      Name: Link, Type: String
      _result.channel.link
      Name: ID, Type: String
      _NULL
  2. Hover over the XML action and select out
  3. Create a  Save action
    1. Primary Table: BBC_News

Save Action and Open Screen Action Setup

  1. Click on the connector between the XML action and the Save action
  2. Map across the XML attributes to their relevant attributes on the Save action

     How?

Testing

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


1.02 Actionflow Principles

  • No labels