XML Validate Action Configuration

What is an XML Validate Action?

  XML Validate actions verify that the elements, attributes or data types used in XML data matches those specified in a   XML Schema Definition.

Creating XML Validate Actions

  1. Click and drag the   XML Validate icon from the toolbar onto the canvas
  2. Enter a name for the XML Validate action, then select Create Action
  3. In the XML Validate action  Properties on the right, populate the following details:
FieldDescriptionExample Value
NameName given to the XML Validate node. This will be displayed on the Actionflow canvas.MyXMLValidator
Root Schema Definition

The primary   XML Schema Definition that will be used to validate an XML document passed to the node.

MyXSD

4. Further XML Schema Definitions can be applied in the XML Schema Definitions section

5.  Apply and Close all settings

Creating XML Schema Definitions

  XML Schema Definitions (XSD) define the rules, constraints and structure an XML document should adhere to.

  1. In the XML Validate action  Properties, in the XML Schema Definitions section, click the   button to display existing XML Schema Definitions in the application
    1. These can be dragged across into the XML Schema Definitions section on the XML Validate action
  2. Create a new schemas by selecting the button
  3. In the  Properties, populate the following details:


FieldDescriptionExample Value
NameName given to the XML Schema Definition. MyXDS
NamespaceThe URI used to reference it. This should be unique within the application.http://www.w3.org/TR/html4/
Schema Definition Body

The contents of the XSD in text.

 Show example
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="
schemaLocation="atom.xsd"/>
<xs:import namespace="
schemaLocation="test2.xsd"/>
 
<xs:element name="url" type="xs:string"/>
<xs:element name="title" type="xs:string"/>
<xs:element name="link" type="xs:string"/>
<xs:element name="description" type="xs:string"/>
<xs:element name="guid">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="isPermaLink" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="pubDate" type="xs:string"/>
<xs:element name="image">
<xs:complexType>
<xs:sequence>
<xs:element ref="url"/>
<xs:element ref="title"/>
<xs:element ref="link"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="generator" type="xs:string"/>
<xs:element name="lastBuildDate" type="xs:string"/>
<xs:element name="copyright" type="xs:string"/>
<xs:element name="language" type="xs:string"/>
<xs:element name="ttl" type="xs:byte"/>
<xs:element name="item">
<xs:complexType>
<xs:sequence>
<xs:element ref="title"/>
<xs:element ref="description"/>
<xs:element ref="link"/>
<xs:element ref="guid"/>
<xs:element ref="pubDate"/>
<xs:element ref="mrss:thumbnail" xmlns:mrss="http://search.yahoo.com/mrss/"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="channel">
<xs:complexType>
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element ref="title"/>
<xs:element ref="description"/>
<xs:element ref="link"/>
<xs:element ref="image"/>
<xs:element ref="generator"/>
<xs:element ref="lastBuildDate"/>
<xs:element ref="atom:link" xmlns:atom="http://www.w3.org/2005/Atom"/>
<xs:element ref="copyright"/>
<xs:element ref="language"/>
<xs:element ref="ttl"/>
<xs:element ref="item"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="rss">
<xs:complexType>
<xs:sequence>
<xs:element ref="channel"/>
</xs:sequence>
<xs:attribute type="xs:float" name="version"/>
</xs:complexType>
</xs:element>
</xs:schema>

XML Validate Action Attributes

NameDescriptionUse
xml

A target parameter on the   XML Validate action that can be mapped onto. 

Map the XML document to be validated to this attribute. 
error

An output attribute found on the error output connection point of the   XML Validate action.

Contains an error message, if applicable.

Worked Example

Here is a worked example using an XML file from the 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

Prerequisites 

For this example, we'll validate an XML file from the BBC News. If you have not completed the worked example in XML Action Configuration, expand the section below and follow the steps to create an Actionflow that retrieves, transforms and saves XML data.

 Create an RSS Feed using XML Data

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  Table on your  ERD 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  HTTP 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  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
  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 PhixFlow to process
  7. Connect the out connector from the  HTTP to the XML action
    1. Map across the attribute, body

       Checkpoint


XML Action Setup

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

      Name: Title, Type: String
      _result.title
      Name: Description, Type: Bigstring
      _result.description
      Name: Link, Type: String
      _result.link
      Name: ID, Type: String
      _NULL
      Name: Date, Type: Datetime
      do(
      	$dater = replaceAll(_result.pubDate, " GMT", ""),
      	$dater = substring($dater, 6),
      	
      	toDate($dater, "dd MMM yyyy HH:mm:ss")
      )
      Name: Source, Type: String
      _result.^.title
  2. Hover over the XML action and select out
  3. Create a  Save action
    1. Primary Table: The News table you created earlier
    2. Map across the XML attributes to their relevant attributes on the Save action

       How?

Screen Setup

  1. Open the Shop News screen
  2. Click on  Attributes 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  Grid

Testing

  1. On the Shop News screen,  Lock 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

Validate XML using an XSD

In this example, we'll validate the XML data from the BBC News is in a required format. To do this we'll create a   XML Schema Definition (XSD).

Roll Back Table 

Once you have completed the above example, the table you created to save the news data to will contain data. We'll roll this back before we complete the next steps as we'll be populating it again after the XML has been validated.

  1. Find your table in the  Repository
  2. Right-click it and choose Rollback Selected Objects
  3. Select Rollback all data 
  4. Toggle off Keep Old Recordsets
  5. Click Confirm 

Configure XML Validate Action

  1. Open the Actionflow on the Start RSS Feed button
  2. Click and drag the   XML Validate icon from the toolbar onto the canvas
  3. Enter a name for the XML Validate action, then select Create Action
  4. The  Properties will open on the right
  5. Drag and drop the node between the  HTTP and the  XML
  6. Map across the body attribute from the HTTP action onto the xml attribute on the XML Validate action

Set up Error Handling

  1. Create a  Calculate action
  2. Connect the error output connection on the   XML Validate action to the Calculate action
  3. Map across the error attribute
  4. Create an Output Attribute to display any errors in the System Console
    1. Name: MyErrorMsg
    2. Type: String
    3. Expression:

      debug("XML failed validation due to: " + in.error)

Set up the Root Schema Definition

  1. In the XML Validate action properties, click the button next to Root Schema Definition to create a new XSD
  2. In the   XML Schema Definition  Properties enter:
    1. Name: BBC Feed XSD
    2. Namespace: BBCFeed
    3. Schema Definition Body: 

      <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:import namespace="
      http://www.w3.org/2005/Atom"
      schemaLocation="atom.xsd"/>
      <xs:import namespace="
      http://search.yahoo.com/mrss/"
      schemaLocation="test2.xsd"/>
      
      <xs:element name="url" type="xs:string"/>
      <xs:element name="title" type="xs:string"/>
      <xs:element name="link" type="xs:string"/>
      <xs:element name="description" type="xs:string"/>
      <xs:element name="guid">
      <xs:complexType>
      <xs:simpleContent>
      <xs:extension base="xs:string">
      <xs:attribute type="xs:string" name="isPermaLink" use="optional"/>
      </xs:extension>
      </xs:simpleContent>
      </xs:complexType>
      </xs:element>
      <xs:element name="pubDate" type="xs:string"/>
      <xs:element name="image">
      <xs:complexType>
      <xs:sequence>
      <xs:element ref="url"/>
      <xs:element ref="title"/>
      <xs:element ref="link"/>
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      <xs:element name="generator" type="xs:string"/>
      <xs:element name="lastBuildDate" type="xs:string"/>
      <xs:element name="copyright" type="xs:string"/>
      <xs:element name="language" type="xs:string"/>
      <xs:element name="ttl" type="xs:byte"/>
      <xs:element name="item">
      <xs:complexType>
      <xs:sequence>
      <xs:element ref="title"/>
      <xs:element ref="description"/>
      <xs:element ref="link"/>
      <xs:element ref="guid"/>
      <xs:element ref="pubDate"/>
      <xs:element ref="mrss:thumbnail" xmlns:mrss="http://search.yahoo.com/mrss/"/>
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      <xs:element name="channel">
      <xs:complexType>
      <xs:choice maxOccurs="unbounded" minOccurs="0">
      <xs:element ref="title"/>
      <xs:element ref="description"/>
      <xs:element ref="link"/>
      <xs:element ref="image"/>
      <xs:element ref="generator"/>
      <xs:element ref="lastBuildDate"/>
      <xs:element ref="atom:link" xmlns:atom="http://www.w3.org/2005/Atom"/>
      <xs:element ref="copyright"/>
      <xs:element ref="language"/>
      <xs:element ref="ttl"/>
      <xs:element ref="item"/>
      </xs:choice>
      </xs:complexType>
      </xs:element>
      <xs:element name="rss">
      <xs:complexType>
      <xs:sequence>
      <xs:element ref="channel"/>
      </xs:sequence>
      <xs:attribute type="xs:float" name="version"/>
      </xs:complexType>
      </xs:element>
      </xs:schema>
    4. Click  Apply and Close on the  XML Schema Definition tab
    5. Click  Apply on the   XML Validate tab

Set up XML Schema Definitions

Set up two further schema definitions.

  1. In the properties of the   XML Validate action, click the    button in the XML Schema Definition section
  2. Create two more XML Schema Definitions, with the following setup:
    1. Name: atom
      1. Namespace: http://www.w3.org/2005/Atom
      2. Schema Definition Body: 

        <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.w3.org/2005/Atom" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="link">
        <xs:complexType>
        <xs:simpleContent>
        <xs:extension base="xs:string">
        <xs:attribute type="xs:string" name="href"/>
        <xs:attribute type="xs:string" name="rel"/>
        <xs:attribute type="xs:string" name="type"/>
        </xs:extension>
        </xs:simpleContent>
        </xs:complexType>
        </xs:element>
        </xs:schema>
    2. Name: thumbnail
      1. Namespace: http://search.yahoo.com/mrss/
      2. Schema Definition Body: 

        <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://search.yahoo.com/mrss/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="thumbnail">
        <xs:complexType>
        <xs:simpleContent>
        <xs:extension base="xs:string">
        <xs:attribute type="xs:short" name="width" use="optional"/>
        <xs:attribute type="xs:short" name="height" use="optional"/>
        <xs:attribute type="xs:string" name="url" use="optional"/>
        </xs:extension>
        </xs:simpleContent>
        </xs:complexType>
        </xs:element>
        </xs:schema>
  3. Drag both atom and thumbnail into the XML Schema Definition section on the   XML Validate action

Run the Actionflow

  1. Run the Actionflow again using the button on the screen
  2. The Actionflow should run successfully

Create a Validation Failure (Optional)

If you wish to see your error handling in action, modify any of your XML Schema Definitions so that the validation fails and you see your error message in the System Console.