如何创建从类XSD模式? [英] How to create a XSD schema from a class?

查看:124
本文介绍了如何创建从类XSD模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很难与XSD文件。

I'm having a hard time with the XSD files.

我试图创建一个类XSD文件:

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
{
    // ...
}

请注意,我所拥有的配置里面的抽象类。由于这一特点,是有可能创造的XSD,如果有可能如何?

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?

我们的想法是对类配置传递到XSD。

The idea is to pass the class Configuration to the XSD.

推荐答案

您可以使用 XSD.EXE (可从您的Visual Studio安装。)

You can use XSD.exe (Available from your Visual Studio Installation.)

public sealed class Configuration
{
 public string Name { get; set; }
 public Levels Level { get; set; }
 public ConfigurationSpec Spec { get; set; }
}
 public abstract class ConfigurationSpec { }
 public class ConfigurationSpec1    {   }
public class ConfigurationSpec2 {   }

结果

<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Levels" type="Levels" />
  <xs:simpleType name="Levels">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Easy" />
      <xs:enumeration value="Medium" />
      <xs:enumeration value="Hard" />
    </xs:restriction>
  </xs:simpleType>
  <xs:element name="Configuration" nillable="true" type="Configuration" />
  <xs:complexType name="Configuration">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="1" name="Name" type="xs:string" />
      <xs:element minOccurs="1" maxOccurs="1" name="Level" type="Levels" />
      <xs:element minOccurs="0" maxOccurs="1" name="Spec" type="ConfigurationSpec" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="ConfigurationSpec" abstract="true" />
  <xs:element name="ConfigurationSpec" nillable="true" type="ConfigurationSpec" />
  <xs:element name="ConfigurationSpec1" nillable="true" type="ConfigurationSpec1" />
  <xs:complexType name="ConfigurationSpec1" />
  <xs:element name="ConfigurationSpec2" nillable="true" type="ConfigurationSpec2" />
  <xs:complexType name="ConfigurationSpec2" />
</xs:schema>

所有你需要做的就是编译你的组装和运行 XSD.EXE 的路径,你的程序集作为参数。 XSD.EXE /?拥有的所有参数列表,以及

All you have to do is compiling your assembly and run XSD.exe with the path to your assembly as argument. XSD.exe /? has a list of all arguments as well.

例如: XSD.EXE C:\\开发\\ PROJECT1 \\ BIN \\调试\\ library.dll

这篇关于如何创建从类XSD模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆