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
- Click and drag the XML Validate icon from the toolbar onto the canvas
- Enter a name for the XML Validate action, then select Create Action
- In the XML Validate 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 XML Schema Definition that will be used to validate an XML document passed to the node. |
|
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.
- In the XML Validate action Properties, in the XML Schema Definitions section, click the 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 button
- In the Properties, populate the following details:
The contents of the XSD in text.Field Description Example Value Name Name given to the XML Schema Definition. MyXDS
Namespace The URI used to reference it. This should be unique within the application. http://www.w3.org/TR/html4/ Schema Definition Body
XML Validate Action Attributes
Name | Description | Use |
---|---|---|
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:
- 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.
Prerequisites
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
Configure XML Validate Action
- Open the Actionflow on the Start RSS Feed button
- Click and drag the XML Validate icon from the toolbar onto the canvas
- Enter a name for the XML Validate action, then select Create Action
- The Properties will open on the right
- Drag and drop the node between the HTTP and the XML
- Map across the body attribute from the HTTP action onto the xml attribute on the XML Validate action
Set up Error Handling
- Create a Calculate action
- Connect the error output connection on the XML Validate 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:
debug("XML failed validation due to: " + in.error)
- Name:
Set up the Root Schema Definition
- In the XML Validate action properties, click the button next to Root Schema Definition to create a new XSD
- In the XML Schema Definition Properties enter:
- Name:
BBC Feed XSD
- Namespace:
BBCFeed
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>
- Click Apply and Close on the XML Schema Definition tab
- Click Apply on the XML Validate tab
- Name:
Set up XML Schema Definitions
Set up two further schema definitions.
- In the properties of the XML Validate action, click the 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:
<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>
- Namespace:
- Name:
thumbnail
- Namespace:
http://search.yahoo.com/mrss/
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>
- Namespace:
- Name:
- Drag both atom and thumbnail into the XML Schema Definition section on the XML Validate 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.