Show All Projects
This is a script that will generate a class to represent an object from either serialized XML, a DTD file, or an XSD file. It requires the xsd.exe utility which is included with Visual Studio and the Windows Platform SDK. Java is required if converting DTD. Original batch script rewritten in Powershell to be more robust and an exercise to learn Powershell.

  • XML-DTD-XSD-To-Class.cmd - Original batch script.
  • XML-DTD-XSD-To-Class.ps1 - More robust version written in Powershell.
  • XML-DTD-XSD-To-Class.ps1.cmd - Runs the powershell version more conveniently, overcoming a few obstacles.

How It Works
Drag and drop a file on to either of the cmd files, or from the command line, pass a path to an xml, dtd, or xsd file. The Powershell version takes an optional second parameter to set the output language. The output language can be 'CS', 'VB', 'JS', 'VJS', 'CPP' or any "fully-qualified name for a class implementing System.CodeDom.Compiler.CodeDomProvider."

As a first step, XML or DTD will be converted to XSD.
DTD is converted to XSD by Trang (included), which requires that Java is installed.
XML is converted to XSD by xsd.exe. The Powershell version should find xsd.exe automatically if installed, while the batch script checks static paths which would will need to be updated for newer versions.

XSD is then converted to code using xsd.exe.

Note that the xsd.exe can sometimes produce code where there is an array of arrays where there should only be an array. Code may need to be checked for this.