Skip to content
Tools for extracting information from Xml schemas and generating checking code
C# Other
  1. C# 98.1%
  2. Other 1.9%
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Build Status
Built with Nuke

Online Documentation

This packages purpose is to correct invalid Xml files where enumeration restrictions or Xml date format masks are violated. It's intended to make working with code generated from Xml schemas easier.

While it can be used dynamically (see XmlTools.Tests.CodeGenerator.SchemaCorrectorHelper for dynamically generating the code, compiling in-memory with Roslyn and then working with this code), it's main use case is to auto generate code that is then used to sanitize incoming Xml.

Features are currently limited to correcting Xml enumeration restrictions, fixing invalid Xsd decimals and repairing or removing invalid Xml date elements. Both attributes and elements are supported. When an invalid enumeration value is encountered, it is either deleted if it's not valid at all or case corrected if the casing is off.

Using the XmlTools.Console app to create validation code

With the package available in the local NuGet cache, you need to create two files:


    Powershell.exe -executionpolicy remotesigned -File  "%~dp0\codegen.ps1" Schema\MySchema.xsd Schema\MySchemaCorrector.cs MyNamespace


param([string]$inputPath, [string]$outputPath, [string]$namespace)
# Find the latest version of the XmlTools.Console app
$xmlToolPackages = Join-Path -Path $env:USERPROFILE -ChildPath "\.nuget\packages\XmlTools.Console"
$latestXmlToolConsoleApp = Join-Path -Path ((Get-ChildItem -Path $xmlToolPackages | Sort-Object Fullname -Descending)[0].FullName) -ChildPath "tools\net461\XmlTools.Console.exe"
# Call the tool to make the conversion
& $latestXmlToolConsoleApp -i $inputPath -o $outputPath -n $namespace

Specify the input schema, output code file and the namespace in the batch file and call it whenever you want to recreate your code.

Main classes

There's the XmlSchemaParser in XmlTools.Parser to read Xml schemas and then there's the XmlSchemaCorrectorGenerator in XmlTools.CodeGenerator to create validation code.


The function of the XmlTools.GroupFlattener.Flattener is to flatten or unroll groups. Many Xml tools have trouble with resolving circular group references, so this is an easy way to fix this while still preserving the schema. In addition, it makes sure that any elements of type xs:key will have their unique naming restored.

The group flattener supports an optional argument of type List<string> to only flatten groups with the given names. This is sometimes useful to only flatten groups that resolve to a circular reference, which may cause errors with some Xsd-to-Code generators.

You can’t perform that action at this time.