Xsd.exe或Svcutil.exe将XSD架构转换为类

时间:2022-01-14 17:18:02

Is it so that svcutil tool is recommended over xsd tool? I didn't see that as a confirmed statement, but it did seem so. The reason that I am confused over this is that I generated a class using both the tools. But, I got a better class using xsd. The XSD schema consists of DataContracts only.

是否建议使用svcutil工具而不是xsd工具?我没有看到这是一个确认的声明,但它似乎确实如此。我对此感到困惑的原因是我使用这两个工具生成了一个类。但是,我使用xsd获得了更好的课程。 XSD架构仅由DataContracts组成。

I used the following command for svcutil:

我对svcutil使用了以下命令:

svcutil path-to\xyz.xsd /language:C# /dataContractOnly /importxmltypes /out:path-to\class.cs

This generated the desired classes. But, it contained only XmlNode[] objects for the fields.

这产生了所需的类。但是,它只包含字段的XmlNode []对象。

Then, I used the following command for xsd:

然后,我对xsd使用了以下命令:

xsd.exe /c path-to\xyz.xsd /out:path-to\class.cs

It generated much better classes than svcutil did. Most of the fields were converted as desired.

它产生了比svcutil更好的类。大多数字段都按需转换。

Should I have any reason to believe that I should use svcutil over xsd then?

我有理由相信我应该在xsd上使用svcutil吗?

2 个解决方案

#1


5  

As far as I know, there are some limitations with XSD.exe; for instance when there is a Dictionary<,> in the class, XSD.exe can not generate a proper XSD; as Dictionary does not implement IXmlSerializable.

据我所知,XSD.exe存在一些局限性;例如,当类中有Dictionary <,>时,XSD.exe无法生成正确的XSD;因为Dictionary没有实现IXmlSerializable。

#2


2  

svcutil does not support xml attributes. If you need to use them in your schema, you are probably better off with xsd.exe.

svcutil不支持xml属性。如果您需要在架构中使用它们,那么使用xsd.exe可能会更好。

I personally prefer to use svcutil over xsd and I've learned how to form my schemas to output the class structure I want, but I'm also primarily working with schemas that I am developing from scratch, as opposed to consuming predefined ones.

我个人更喜欢在xsd上使用svcutil并且我已经学会了如何形成我的模式以输出我想要的类结构,但我也主要使用我从头开发的模式,而不是使用预定义的模式。

#1


5  

As far as I know, there are some limitations with XSD.exe; for instance when there is a Dictionary<,> in the class, XSD.exe can not generate a proper XSD; as Dictionary does not implement IXmlSerializable.

据我所知,XSD.exe存在一些局限性;例如,当类中有Dictionary <,>时,XSD.exe无法生成正确的XSD;因为Dictionary没有实现IXmlSerializable。

#2


2  

svcutil does not support xml attributes. If you need to use them in your schema, you are probably better off with xsd.exe.

svcutil不支持xml属性。如果您需要在架构中使用它们,那么使用xsd.exe可能会更好。

I personally prefer to use svcutil over xsd and I've learned how to form my schemas to output the class structure I want, but I'm also primarily working with schemas that I am developing from scratch, as opposed to consuming predefined ones.

我个人更喜欢在xsd上使用svcutil并且我已经学会了如何形成我的模式以输出我想要的类结构,但我也主要使用我从头开发的模式,而不是使用预定义的模式。