Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xsd.exe or Svcutil.exe to convert XSD schema to a class

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.

I used the following command for 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.

Then, I used the following command for 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.

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

like image 647
Jayesh Bhoot Avatar asked Mar 23 '12 09:03

Jayesh Bhoot


People also ask

What is XSD exe?

The XML Schema Definition (Xsd.exe) tool generates XML schema or common language runtime classes from XDR, XML, and XSD files, or from classes in a runtime assembly.

Where can I find XSD exe?

You can find you xsd.exe in the following location (depending upon . net version installed on your pc): C:\Program Files (x86)\Microsoft SDKs\Windows\v10.

What is the use of XSD file in C#?

XSD is a schema language; you use it to define the possible structure and contents of an XML format. A validating parser can then check whether an XML instance document conforms to an XSD schema or a set of schemas.


1 Answers

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.

like image 144
daryal Avatar answered Nov 15 '22 12:11

daryal