svcutil.exe的是对XSD.EXE的替代品? [英] Is svcutil.exe a replacement for xsd.exe?
问题描述
我使用XSD.EXE生成从.xsd文件的一些C#类。我跑到了这里所涉及的同样的问题,在哪里产生XSD.EXE在.xsd文件类型[]数组来代替泛型列表集合了各类其他网站。有些人建议,svcutil.exe的可以,如果你通过/ dataContractOnly参数svcutil.exe的被用作XSD.EXE的替代品。但是,好像那些人是错误的,因为svcutil.exe的实际产生System.Xml.XmlNode []数组属性,而不是基于.xsd文件的模式创建的类型。
例如,考虑这个简单的.xsd架构:
< XML版本=1.0编码=UTF -8>?;
< XS:架构的targetNamespace =http://tempuri.org/XMLSchema.xsd
将elementFormDefault =合格
的xmlns =http://tempuri.org/XMLSchema。 XSD
的xmlns:mstns =http://tempuri.org/XMLSchema.xsd
的xmlns:XS =http://www.w3.org/2001/XMLSchema
>
< XS:复杂类型名称=雇员>
< XS:所有与GT;
< XS:元素的名称=名字类型=XS:字符串>< / XS:组件>
< XS:元素的名称=姓氏类型=XS:字符串>< / XS:组件>
< / XS:所有与GT;
< / XS:复杂类型>
< XS:元素的名称=员工>
< XS:复杂类型>
< XS:序列的maxOccurs =无界>
< XS:元素的名称=雇员TYPE =雇员>< / XS:组件>
< / XS:序列>
< / XS:复杂类型>
< / XS:组件>
< / XS:架构>
XSD.EXE /班Example.xsd'产生:
公共部分类员工{
私人雇员[] employeeField;
公务员[] {员工
{返回this.employeeField; }
集合{this.employeeField =价值; }
}
}
公共部分类Employee {
私人字符串firstNameField;
私人字符串lastNameField;
公共字符串名字{
{返回this.firstNameField; }
集合{this.firstNameField =价值; }
}
公共字符串名字{
{返回this.lastNameField; }
集合{this.lastNameField =价值; }
}
}
svcutil.exe的/目标:代码/ dataContractOnly /串行器:XmlSerializer的/ importXmlTypes /collectionType:System.Collections.Generic.List`1 Example.xsd'产生:
公共部分Employee类:对象,System.Runtime.Serialization.IExtensibleDataObject {
私人System.Runtime.Serialization.ExtensionDataObject extensionDataField;
私人字符串FirstNameField;
私人字符串LastNameField;
公共System.Runtime.Serialization.ExtensionDataObject ExtensionData {
{返回this.extensionDataField; }
集合{this.extensionDataField =价值; }
}
公共字符串名字{
{返回this.FirstNameField; }
集合{this.FirstNameField =价值; }
}
公共字符串名字{
{返回this.LastNameField; }
集合{this.LastNameField =价值; }
}
}
公共部分类员工:对象,System.Xml.Serialization.IXmlSerializable {
私人System.Xml.XmlNode [] nodesField;
私有静态System.Xml.XmlQualifiedName的typeName =新System.Xml.XmlQualifiedName(员工,http://tempuri.org/XMLSchema.xsd);
公共System.Xml.XmlNode [] {节点
{返回this.nodesField; }
集合{this.nodesField =价值; }
}
公共无效的ReadXml(System.Xml.XmlReader读者){
this.nodesField = System.Runtime.Serialization.XmlSerializableServices.ReadNodes(读卡器);
}
公共无效中WriteXML(System.Xml.XmlWriter作家){
System.Runtime.Serialization.XmlSerializableServices.WriteNodes(作家,this.Nodes);
}
公共System.Xml.Schema.XmlSchema的getSchema(){
返回NULL;
}
公共静态System.Xml.XmlQualifiedName ExportSchema(System.Xml.Schema.XmlSchemaSet模式){
System.Runtime.Serialization.XmlSerializableServices.AddDefaultSchema(架构,typeName的) ;
回报率的typeName;
}
}
-
是svcutil.exe的真的要成为XSD.EXE更换?生成的输出似乎是完全不同的。
-
在这一点上,它看起来像我将不得不使用XSD.EXE从我的.xsd文件创建类然后手动调整的代码来得到它我想要的形式。我认识到,单纯使用生成的代码将是理想的,但如果其他人正在使用XSD.EXE作为起点,然后从那里工作或我在想,如果我需要完全考虑另一种方法?
-
是否有任何更新,在Visual Studio 2010 XSD.EXE?
是 svcutil.exe的
的可以EM>使用作为 XSD的替代品。 exe文件
,但它听起来像你不必会产生麻烦泛型集合。 svcutil.exe的
已经用于集合的 collectionType
开关,允许你指定类型:
SvcUtil工具/o:Svc.cs /ct:System.Collections.Generic.List`1 http://example.com
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.
For example, given this simple .xsd schema:
<?xml version="1.0" encoding="utf-8"?>
<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"
>
<xs:complexType name="Employee">
<xs:all>
<xs:element name="FirstName" type="xs:string"></xs:element>
<xs:element name="LastName" type="xs:string"></xs:element>
</xs:all>
</xs:complexType>
<xs:element name="Employees">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="Employee" type="Employee"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
'xsd.exe /classes Example.xsd' generates:
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; }
}
}
'svcutil.exe /target:code /dataContractOnly /serializer:XmlSerializer /importXmlTypes /collectionType:System.Collections.Generic.List`1 Example.xsd' generates:
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;
}
}
Is svcutil.exe really supposed to be a replacement for xsd.exe? The output generated seems to be quite different.
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?
Are there any updates to xsd.exe in Visual Studio 2010?
Yes, svcutil.exe
can be used as a replacement for xsd.exe
but it sounds like you are having trouble getting generic collections to be generated. svcutil.exe
has a collectionType
switch that allows you to specify the type to be used for a collection:
svcutil /o:Svc.cs /ct:System.Collections.Generic.List`1 http://example.com
这篇关于svcutil.exe的是对XSD.EXE的替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!