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)
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.
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.
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".
NOTE! Windows will block DLLs from the Internet, so once the DLL is on your PC, right click it, select "Show More Options", select "Properties", and on the General tab at the bottom you may see "This file came from another computer and might be blocked to help protect this computer. Here there is a checkbox without a checkmark (tick) in it called Unblock. Check the checkbox to unblock the DLL, otherwise Windows will refuse to let it work.
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 <~~~>.
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.
Steve Hibbert (steve at Continuum dot je), October 2017 (www.continuum.je)
This code is the IP of Continuum Jersey.
- StackOverflow; For catching me when I fall.
- James Dunkerly, Alteryx ACE, for invaluable help over time.