[英]Xsd.exe or Svcutil.exe to convert XSD schema to a class
Is it so that svcutil tool is recommended over xsd tool? 是否建议使用svcutil工具而不是xsd工具? 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.
但是,我使用xsd获得了更好的课程。 The XSD schema consists of DataContracts only.
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. 它产生了比svcutil更好的类。 Most of the fields were converted as desired.
大多数字段都按需转换。
Should I have any reason to believe that I should use svcutil over xsd then? 我有理由相信我应该在xsd上使用svcutil吗?
As far as I know, there are some limitations with XSD.exe; 据我所知,XSD.exe存在一些局限性; for instance when there is a
Dictionary<,>
in the class, XSD.exe can not generate a proper XSD; 例如,当类中有
Dictionary<,>
时,XSD.exe无法生成正确的XSD; as Dictionary
does not implement IXmlSerializable
. 因为
Dictionary
没有实现IXmlSerializable
。
svcutil does not support xml attributes. svcutil不支持xml属性。 If you need to use them in your schema, you are probably better off with xsd.exe.
如果您需要在架构中使用它们,那么使用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并且我已经学会了如何形成我的模式以输出我想要的类结构,但我也主要使用我从头开发的模式,而不是使用预定义的模式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.