编程语言
首页 > 编程语言> > C#为xml可序列化类创建XSD的最简单方法是什么

C#为xml可序列化类创建XSD的最简单方法是什么

作者:互联网

首先,我是这个主题的新手,在收集了很多背景信息之后,我变得更加困惑.

我有几个类,它们都是可序列化的,有一些实现IXmlSerializable.在适当的位置用[XmlRoot],[XmlAttribute]等标记这些类.

我想知道的是如何使用现有标签为每个类创建一个简单的XSD.我对手动和编程方式都感兴趣.如果可能的话,我宁愿使用VS2008中集成的工具.

解决方法:

好吧,使用IXmlSerializable可以关闭所有赌注,因为无法保证任何模式.但是,其余的:

xsd.exe <assembly>.dll|.exe [/outputdir:] [/type: [...]]

MSDN开始:

/t[ype]:typename Specifies the name of
the type to create a schema for. You
can specify multiple type arguments.
If typename does not specify a
namespace, Xsd.exe matches all types
in the assembly with the specified
type. If typename specifies a
namespace, only that type is matched.
If typename ends with an asterisk
character (*), the tool matches all
types that start with the string
preceding the *. If you omit the /type
option, Xsd.exe generates schemas for
all types in the assembly.

Classes to XSD Generates an XML schema
from a type or types in a runtime
assembly file. The generated schema
defines the XML format used by
System.Xml.Serialization.XmlSerializer.

标签:xsd,visual-studio-2008,c
来源: https://codeday.me/bug/20191108/2004383.html