Versions Compared

Key

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

Insert excerpt
_Banners
_Banners
nameactionflow
nopaneltrue

What is an XML Validate Action?

Insert excerpt
_xml_validate
_xml_validate
nopaneltrue
actions verify that the elements, attributes or data types used in XML data matches those specified in a
Insert excerpt
_xml_validate
_xml_validate
nameschema
nopaneltrue
.

Creating XML Validate Actions

  1. Click and drag the 
    Insert excerpt
    _xml_validate
    _xml_validate
    nopaneltrue
     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  Insert excerpt_property_settings_property_settingsnopaneltrueNode 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

Insert excerpt
_xml_validate
_xml_validate
nameschema
nopaneltrue
 that will be used to validate an XML document passed to the node.

MyXSD

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

5.

Insert excerpt
_finish
_finish
nopaneltrue
 all settings

Creating XML Schema Definitions

Insert excerpt
_xml_validate
_xml_validate
nameschema
nopaneltrue
s (XSD) define the rules, constraints and structure an XML document should adhere to.

  1. In the XML Validate action 
    Insert excerpt
    _property_settings
    _property_settings
    nopaneltrue
    , in the XML Schema Definitions section, click the
    Insert excerpt
    _xml_validate
    _xml_validate
    nameicon
    nopaneltrue
    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
    Insert excerpt
    _addIcon
    _addIcon
    nopaneltrue
    button
  3. In the
    Insert excerpt
    _property_settings
    _property_settings
    nopaneltrue
    , populate the following details:

Insert excerpt
HELP12:HELP12:HELP12:HELP12:XML Schema DefinitionHELP12:HELP12:HELP12:HELP12:
XML Schema Definition
nameSettings
nopaneltrue

XML Validate Action Attributes

NameDescriptionUse
xml

A target parameter on the

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

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

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.

Expand
titleCreate an RSS Feed using XML Data

Insert excerpt
XML Action Configuration
XML Action Configuration
nameXMLActionExample
nopaneltrue

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

Insert excerpt
_xml_validate
_xml_validate
nameschema
nopaneltrue
(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 
    Insert excerpt
    _repository
    _repository
    nopaneltrue
  2. Right-click it and choose 
    Insert excerpt
    _rollback
    _rollback
    nameselected
    nopaneltrue
  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 
    Insert excerpt
    _xml_validate
    _xml_validate
    nopaneltrue
     icon from the toolbar onto the canvas
  3. Enter a name for the XML Validate action, then select Create Action
  4. The
    Insert excerpt
    _property_settings
    _property_settings
    nopaneltrue
    will open on the right
  5. Drag and drop the node between the 
    Insert excerpt
    _action_http
    _action_http
    nopaneltrue
    and the 
    Insert excerpt
    _action_xml
    _action_xml
    nopaneltrue
  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 
    Insert excerpt
    _action_calculate
    _action_calculate
    nopaneltrue
    action
  2. Connect the error output connection on the
    Insert excerpt
    _xml_validate
    _xml_validate
    nopaneltrue
    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:

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


Set up the Root Schema Definition

  1. In the XML Validate action properties, click the
    Insert excerpt
    _addIcon
    _addIcon
    nopaneltrue
    button next to Root Schema Definition to create a new XSD
  2. In the 
    Insert excerpt
    _xml_validate
    _xml_validate
    nameschema
    nopaneltrue
     
    Insert excerpt
    _property_settings
    _property_settings
    nopaneltrue
    enter:
    1. Name: BBC Feed XSD
    2. Namespace: BBCFeed
    3. Schema Definition Body: 

      Code Block
      themeEmacs
      <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 
      Insert excerpt
      _finish
      _finish
      nopaneltrue
      on the
      Insert excerpt
      _xml_validate
      _xml_validate
      nameschema
      nopaneltrue
      tab
    5. Click 
      Insert excerpt
      _save
      _save
      nopaneltrue
      on the 
      Insert excerpt
      _xml_validate
      _xml_validate
      nopaneltrue
      tab

Set up XML Schema Definitions

Set up two further schema definitions.

  1. In the properties of the
    Insert excerpt
    _xml_validate
    _xml_validate
    nopaneltrue
    action, click the  
    Insert excerpt
    _xml_validate
    _xml_validate
    nameicon
    nopaneltrue
    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: 

        Code Block
        themeEmacs
        <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: 

        Code Block
        themeEmacs
        <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
    Insert excerpt
    _xml_validate
    _xml_validate
    nopaneltrue
    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.