如何创建从类XSD模式?

编程入门 行业动态 更新时间:2024-10-25 04:24:36
本文介绍了如何创建从类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="www.w3/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模式?

本文发布于:2023-11-09 05:30:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571509.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模式   XSD

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!