Skip to content

Hiblet/ContinuumXmlValidator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ContinuumXmlValidator

Alteryx C# plug-in to check XML data against one or more XSD Schema files. The tool takes the a field for the XML data, and a second field that contains Windows file paths to the XSD files, and validates the XML data against the set of schema files. An additional output text field is created, and this is either "VALID" or it contains the errors that have caused the XML to fail validation.

This tool is the copyright protected property of Continuum (www.continuum.je)

Introduction

This project is a Windows Visual Studio 2017 project for .Net Framework 4.6.1. It is a Class Library DLL for use with Alteryx, compiled to x64.

XML files can have custom types and rules applied to them. These types and rules are stored in XSD files, and are called the Schema. One schema may reference multiple sub-schemas.

This tool uses the C# XmlSchemaSet object to import and build a set of schemas to apply. The XML data to validate is then parsed in using XDocument.Parse(string). Finally, XDocument.Validate is used to compare the XML data to the schema set, and errors and violations are recorded, and reported in the output field, separated by a "|" (pipe) symbol.

Compilation

You will need Visual Studio 2017 (Community edition is free). You will need Alteryx Designer.

Download the repo and compile the project using Visual Studio 2017. You should end up with a DLL in your debug and release folders. Contact me if you just want a copy of the DLL pre-compiled.

Installation

Assuming you are using the default installation folder:

  • Copy the DLL and PDB files to "C:\Program Files\Alteryx\bin\Plugins\ContinuumXmlValidator".
  • Copy the INI file to "C:\Program Files\Alteryx\Settings\AdditionalPlugins".

Alteryx will discover the plug in tool automatically the next time you start. The tool will then be found using the Alteryx Search function, and you should search for "XmlValidator". The tool should be added to the Developer tool group. The logo is based on the Developer tool series logo (grey cog wheel), with a white hexagon central, containing a tick (check mark) and the standard XML indicator <~~~>.

Usage

The tool expects you to map it to two input fields, and to provide a name for the output field. Other non-referenced fields are passed through.

The XmlData field is the field you should map to your XML string or data that you wish to validate. This field is rudimentally checked to see that it starts with an open angle bracket.

The Schema Field should contain full-path filenames for the XSD files you wish to validate with. Each file name should be separated by a semi-colon delimiter. For example, to use three schema files in C:\MyFiles called A.XSD, B.XSD and C.XSD, the Schema field should contain...

C:\MyFiles\A.XSD;C:\MyFiles\B.XSD;C:\MyFiles\C.XSD

The code does little to process this string, it breaks the string on semi-colons, and then passes each sub-string to the C# StreamReader. The StreamReader type should be able to handle quite a variety of inbound filename formats, so if your full-path filename makes sense, the XSD file should be ingested correctly. Exceptions will be thrown if not.

For relative directory referencing, the Schema file locations are relative to the "C:\Program Files\Alteryx\bin\plugins\ContinuumXmlValidator" folder. This is where the plug-in is running, not the workflow. To use relative referencing based on the workflow folder, the environment variable [Engine.WorkflowDirectory] can be used. This can be referenced in a Formula tool, as if it were a column in the data stream. Therefore, to access a Schema file (as above, A.XSD) that is in a sub-directory of the workflow, you would build a string in a formula tool like this:

[Engine.WorkflowDirectory] + "\Schema\A.XSD"

The Formula tool will substitute in the current working directory, append the string "\Schema\A.XSD", and effectively look in the local workflow sub-directory for the schema file A.XSD .

Note that you can also use the standard backslash directory (meaning the root of the current drive) to reference the schema files. This means that "\Schema\A.XSD" is resolved to "C:\Schema\A.XSD" if the working directory is on the C: drive.

The output field has a default name that can be over-ridden. Output for an XML string that meets the XSD schema requirements is "VALID". Output is otherwise one or more error messages, as generated by the C# XDocument.Validate function. Errors are delimited by a "|" symbol.

Author

Steve Hibbert (steve at Continuum dot je), October 2017 (www.continuum.je)

License

This code is the IP of Continuum Jersey.

Updates

V 1.0.1 : Alpha Release.

V 1.0.2 : Fix for XML Config names.

V 1.0.3 : Record copy process now tolerates non-string types, like Blob.

Credits and Acknowledgements

  • StackOverflow; For catching me when I fall.
  • James Dunkerly, Alteryx ACE, for invaluable help over time.

About

An Alteryx PlugIn Tool to validate an XML string against named XSD Schema files.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages