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 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).FullName) -ChildPath "tools\net461\XmlTools.Console.exe"
# Call the tool to make the conversion
& $latestXmlToolConsoleApp -i $inputPath -o $outputPath -n $namespace
output code file and the
namespace in the batch file and call it
whenever you want to recreate your code.
XmlTools.Parser to read Xml schemas and then there's the
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.