I'm having a hard time with the XSD files.
I'm trying to create an XSD file from a class:
public enum Levels { Easy, Medium, Hard }
public sealed class Configuration
{
public string Name { get;set; }
public Levels Level { get; set; }
public ConfigurationSpec { get;set;}
}
public abstract class ConfigurationSpec { }
public class ConfigurationSpec1
{
// ...
}
public class ConfigurationSpec2
{
// ...
}
Please note that I have an abstract class inside of Configuration. With that feature, is it possible to create the XSD and if it's possible how?
The idea is to pass the class Configuration to the XSD.
You can successfully integrate xsd.exe
into the Visual Studio IDE like this:
Go into Tools, External Tools
and click the Add button:
2010
2015 / 2017
Title:
Create Schema From Class
Command (per framework):
4.0
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\x64\xsd.exe
4.5.1
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64\xsd.exe
4.6.*
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.* Tools\x64\xsd.exe
Arguments:
$(BinDir)$(TargetName).dll /outputdir:$(ItemDir) /type:$(ItemFileName)
Use Output window:
Prevents an extra command window from popping up and keeps a record of the output until you clear it. Probably a good idea.
Prompt For Arguments:
Check if you want to test the output or troubleshoot; otherwise, leave unchecked.
Click OK
How to use:
XSD.exe
only looks at compiled code.Tools, Create Schema From Class
Schema0.xsd
. Schema0.xsd
and choose Include In Project
Schema0.xsd
to <the name of the class>.xsd
xsd
by hand if you want to edit xml files in the xml editor using this schema and you are not using all attributes. You can replace use="required"
with use="optional"
to get rid of the blue squiggly lines in the xml editor (which create warnings), if indeed these attributes are not required.