What is an XML Validate Action?
Insert excerpt |
---|
| _xml_validate |
---|
| _xml_validate |
---|
nopanel | true |
---|
|
actions verify that the elements, attributes or data types used in XML data matches those specified in a
Insert excerpt |
---|
| _xml_validate |
---|
| _xml_validate |
---|
name | schema |
---|
nopanel | true |
---|
|
.
For the full list of XML Validate action
Insert excerpt |
---|
| _property_settings |
---|
| _property_settings |
---|
nopanel | true |
---|
|
, see XML Validate Action Properties, and for XML Schema Definition Insert excerpt |
---|
| _property_settings |
---|
| _property_settings |
---|
nopanel | true |
---|
|
, see XML Schema Definition Properties.Creating XML Validate Actions
- Click and drag the
Insert excerpt |
---|
| _xml_validate |
---|
| _xml_validate |
---|
nopanel | true |
---|
|
icon from the toolbar onto the canvas - Enter a name for the XML Validate action, then select Create Action
- In the XML Validate action
Insert excerpt |
---|
_property_settings | _property_settings | nopanel | true |
Action Properties on the right, populate the following details:
Field | Description | Example Value |
---|
Name | Name 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 |
---|
name | schema |
---|
nopanel | true |
---|
| that will be used to validate an XML document passed to the node. | MyXSD
|
4. Further Further XML Schema Definitions Definition Propertiess can be applied in the XML Schema Definitions section
5.
Insert excerpt |
---|
| _finish |
---|
| _finish |
---|
nopanel | true |
---|
|
all settings
Creating XML Schema Definitions
Insert excerpt |
---|
| _xml_validate |
---|
| _xml_validate |
---|
name | schema |
---|
nopanel | true |
---|
|
s (XSD) define the rules, constraints and structure an XML document should adhere to.
- In the XML Validate action
Insert excerpt |
---|
| _property_settings |
---|
| _property_settings |
---|
nopanel | true |
---|
|
, in the XML Schema Definitions section, click the Insert excerpt |
---|
| _xml_validate |
---|
| _xml_validate |
---|
name | icon |
---|
nopanel | true |
---|
|
button to display existing XML Schema Definitions in the application- These can be dragged across into the XML Schema Definitions section on the XML Validate action
- Create a new schemas by selecting the
Insert excerpt |
---|
| _addIcon |
---|
| _addIcon |
---|
nopanel | true |
---|
|
button - In the
Insert excerpt |
---|
| _property_settings |
---|
| _property_settings |
---|
nopanel | true |
---|
|
, populate the following details:
Insert excerpt |
---|
| HELP12:HELP12:HELP12:HELP12:XML Schema Definition HELP12:HELP12:HELP12:HELP12:Properties |
---|
| XML Schema Definition Properties |
---|
name | Settings |
---|
nopanel | true |
---|
|
XML Validate Action Attributes
Name | Description | Use |
---|
xml | A target parameter on the Insert excerpt |
---|
| _xml_validate |
---|
| _xml_validate |
---|
nopanel | true |
---|
|
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 |
---|
nopanel | true |
---|
|
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:
- A 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 |
---|
title | Create an RSS Feed using XML Data |
---|
|
Insert excerpt |
---|
| XML Action Configuration |
---|
| XML Action Configuration |
---|
name | XMLActionExample |
---|
nopanel | true |
---|
|
|
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 |
---|
name | schema |
---|
nopanel | true |
---|
|
(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.
- Find your table in the
Insert excerpt |
---|
| _repository |
---|
| _repository |
---|
nopanel | true |
---|
|
- Right-click it and choose
Insert excerpt |
---|
| _rollback |
---|
| _rollback |
---|
name | selected |
---|
nopanel | true |
---|
|
- Select Rollback all data
- Toggle off Keep Old Recordsets
- Click Confirm
- Open the Actionflow on the Start RSS Feed button
- Click and drag the
Insert excerpt |
---|
| _xml_validate |
---|
| _xml_validate |
---|
nopanel | true |
---|
|
icon from the toolbar onto the canvas - Enter a name for the XML Validate action, then select Create Action
- The
Insert excerpt |
---|
| _property_settings |
---|
| _property_settings |
---|
nopanel | true |
---|
|
will open on the right - Drag and drop the node between the
Insert excerpt |
---|
| _action_http |
---|
| _action_http |
---|
nopanel | true |
---|
|
and the Insert excerpt |
---|
| _action_xml |
---|
| _action_xml |
---|
nopanel | true |
---|
|
- Map across the body attribute from the HTTP action onto the xml attribute on the XML Validate action
Set up Error Handling
- Create a
Insert excerpt |
---|
| _action_calculate |
---|
| _action_calculate |
---|
nopanel | true |
---|
|
action - Connect the error output connection on the
Insert excerpt |
---|
| _xml_validate |
---|
| _xml_validate |
---|
nopanel | true |
---|
|
action to the Calculate action - Map across the error attribute
- Create an Output Attribute to display any errors in the System Console
- Name:
MyErrorMsg
- Type:
String
Expression:
Code Block |
---|
|
debug("XML failed validation due to: " + in.error) |
Set up the Root Schema Definition
- In the XML Validate action properties, click the
Insert excerpt |
---|
| _addIcon |
---|
| _addIcon |
---|
nopanel | true |
---|
|
button next to Root Schema Definition to create a new XSD - In the
Insert excerpt |
---|
| _xml_validate |
---|
| _xml_validate |
---|
name | schema |
---|
nopanel | true |
---|
|
Insert excerpt |
---|
| _property_settings |
---|
| _property_settings |
---|
nopanel | true |
---|
|
enter:- Name:
BBC Feed XSD
- Namespace:
BBCFeed
Schema Definition Body:
Code Block |
---|
|
<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> |
- Click
Insert excerpt |
---|
| _finish |
---|
| _finish |
---|
nopanel | true |
---|
|
on the Insert excerpt |
---|
| _xml_validate |
---|
| _xml_validate |
---|
name | schema |
---|
nopanel | true |
---|
|
tab - Click on the
Insert excerpt |
---|
| _xml_validate |
---|
| _xml_validate |
---|
nopanel | true |
---|
|
tab
Set up XML Schema Definitions
Set up two further schema definitions.
- In the properties of the
Insert excerpt |
---|
| _xml_validate |
---|
| _xml_validate |
---|
nopanel | true |
---|
|
action, click the Insert excerpt |
---|
| _xml_validate |
---|
| _xml_validate |
---|
name | icon |
---|
nopanel | true |
---|
|
button in the XML Schema Definition section - Create two more XML Schema Definitions, with the following setup:
- Name:
atom
- Namespace:
http://www.w3.org/2005/Atom
Schema Definition Body:
Code Block |
---|
|
<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> |
- Name:
thumbnail
- Namespace:
http://search.yahoo.com/mrss/
Schema Definition Body:
Code Block |
---|
|
<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> |
- Drag both atom and thumbnail into the XML Schema Definition section on the
Insert excerpt |
---|
| _xml_validate |
---|
| _xml_validate |
---|
nopanel | true |
---|
|
action
Run the Actionflow
- Run the Actionflow again using the button on the screen
- 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.