Note that there are some explanatory texts on larger screens.

plurals
  1. POIs svcutil.exe a replacement for xsd.exe?
    primarykey
    data
    text
    <p>I am using xsd.exe to generate some c# classes from a .xsd file. I ran into the same issue that is covered here and on other sites where xsd.exe generates Type[] arrays instead of generic List collections for types in the .xsd file. Some people have suggested that svcutil.exe can be used as a replacement for xsd.exe if you pass the /dataContractOnly parameter to svcutil.exe. However, it seems like those people are mistaken because svcutil.exe actually generates System.Xml.XmlNode[] array properties instead of creating types based on the schema in the .xsd file.</p> <p>For example, given this simple .xsd schema:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:mstns="http://tempuri.org/XMLSchema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" &gt; &lt;xs:complexType name="Employee"&gt; &lt;xs:all&gt; &lt;xs:element name="FirstName" type="xs:string"&gt;&lt;/xs:element&gt; &lt;xs:element name="LastName" type="xs:string"&gt;&lt;/xs:element&gt; &lt;/xs:all&gt; &lt;/xs:complexType&gt; &lt;xs:element name="Employees"&gt; &lt;xs:complexType&gt; &lt;xs:sequence maxOccurs="unbounded"&gt; &lt;xs:element name="Employee" type="Employee"&gt;&lt;/xs:element&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:schema&gt; </code></pre> <p>'xsd.exe /classes Example.xsd' generates:</p> <pre><code>public partial class Employees { private Employee[] employeeField; public Employee[] Employee { get { return this.employeeField; } set { this.employeeField = value; } } } public partial class Employee { private string firstNameField; private string lastNameField; public string FirstName { get { return this.firstNameField; } set { this.firstNameField = value; } } public string LastName { get { return this.lastNameField; } set { this.lastNameField = value; } } } </code></pre> <p>'svcutil.exe /target:code /dataContractOnly /serializer:XmlSerializer /importXmlTypes /collectionType:System.Collections.Generic.List`1 Example.xsd' generates:</p> <pre><code>public partial class Employee : object, System.Runtime.Serialization.IExtensibleDataObject{ private System.Runtime.Serialization.ExtensionDataObject extensionDataField; private string FirstNameField; private string LastNameField; public System.Runtime.Serialization.ExtensionDataObject ExtensionData{ get{ return this.extensionDataField; } set{ this.extensionDataField = value; } } public string FirstName{ get{ return this.FirstNameField; } set{ this.FirstNameField = value; } } public string LastName{ get{ return this.LastNameField; } set{ this.LastNameField = value; } } } public partial class Employees : object, System.Xml.Serialization.IXmlSerializable{ private System.Xml.XmlNode[] nodesField; private static System.Xml.XmlQualifiedName typeName = new System.Xml.XmlQualifiedName("Employees", "http://tempuri.org/XMLSchema.xsd"); public System.Xml.XmlNode[] Nodes{ get{ return this.nodesField; } set{ this.nodesField = value; } } public void ReadXml(System.Xml.XmlReader reader){ this.nodesField = System.Runtime.Serialization.XmlSerializableServices.ReadNodes(reader); } public void WriteXml(System.Xml.XmlWriter writer){ System.Runtime.Serialization.XmlSerializableServices.WriteNodes(writer, this.Nodes); } public System.Xml.Schema.XmlSchema GetSchema(){ return null; } public static System.Xml.XmlQualifiedName ExportSchema(System.Xml.Schema.XmlSchemaSet schemas){ System.Runtime.Serialization.XmlSerializableServices.AddDefaultSchema(schemas, typeName); return typeName; } } </code></pre> <ol> <li><p>Is svcutil.exe really supposed to be a replacement for xsd.exe? The output generated seems to be quite different.</p></li> <li><p>At this point, it looks like I will have to use xsd.exe to create classes from my .xsd file and then manually tweak the the code to get it in the form I want. I realize that using purely generated code would be ideal, but I was wondering if other people are using xsd.exe as a starting point and then working from there or if I need to consider another approach altogether?</p></li> <li><p>Are there any updates to xsd.exe in Visual Studio 2010?</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload