- Created by Zoe Baldwin, last modified on Oct 11, 2024
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 19 Current »
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
- Click and drag the XML icon from the toolbar onto the canvas
- Enter a name for the XML action, then select Create Action
- In the XML action Properties on the right, populate the following details:
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. Apply and Close 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 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. |
^ | 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
<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 Data | Expression | Returns |
---|---|---|
XPath value | _result | PF Title Text |
XPath element attributes | _result.name | PF Title |
XPath parent attributes |
| PF Main Page |
XPath child attributes | listToString(_result.datarow.data.initials) | AA,BB |
XPath child attribute text values | listToString(_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 Data | Expression | Returns |
---|---|---|
XPath element attributes |
| PF Title |
XPath child attributes | listToString(_result.h$datarow.h$data.h$initials) | AA,BB |
XPath child attribute text values | listToString(_result.h$datarow.h$data.value) | 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:
- A 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.
In this example, we'll create a table containing BBC News from an XML file. Map across the attribute, body Output Attributes: Map across the XML attributes to their relevant attributes on the Save actionCreate an RSS Feed using XML Data
Table Setup
UID
Integer
_NULL
Title
String
_NULL
Description
Bigstring
_NULL
Link
String
_NULL
Date
Datetime
_NULL
Source
String
_NULL
Actionflow Setup
XML Action Setup
in.body
/rss/channel/item
_result.title
_result.description
_result.link
_NULL
do(
$dater = replaceAll(_result.pubDate, " GMT", ""),
$dater = substring($dater, 6),
toDate($dater, "dd MMM yyyy HH:mm:ss")
)
_result.^.title
Screen Setup
Testing
On this page
- No labels