C# XSD.exe/dataset没有从我的XSD文件创建枚举

C# XSD.exe/dataset没有从我的XSD文件创建枚举,c#,.net,xsd,xml-serialization,xsd.exe,C#,.net,Xsd,Xml Serialization,Xsd.exe,我创建了一个XSD,并在该.XSD文件上运行了XSD.exe。似乎我的简单类型(仅限于枚举值)没有在输出的.cs文件中生成为枚举 例如,我的xsd如下所示: <xs:element name="ItemList" nillable="false"> <xs:complexType> <xs:sequence minOccurs="1" maxOccurs="1"> <xs:element name="Ite

我创建了一个XSD,并在该.XSD文件上运行了XSD.exe。似乎我的简单类型(仅限于枚举值)没有在输出的.cs文件中生成为枚举

例如,我的xsd如下所示:

<xs:element name="ItemList" nillable="false">
    <xs:complexType>
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="Item" type="ItemType" minOccurs="1" maxOccurs="unbounded" nillable="false">
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:complexType name="ItemType">
    <xs:sequence maxOccurs="1" minOccurs="1">
        <!-- other complex types, etc... -->
    </xs:sequence>
    <xs:attribute name="Market" type="MarketType" use="required">
    </xs:attribute>
    <xs:attribute name="Category" type="CategoryType" use="required" />
</xs:complexType>
<xs:simpleType name="CategoryType">
    <xs:restriction base="xs:string">
        <xs:enumeration value="Mild" />
        <xs:enumeration value="Hot" />
    </xs:restriction>
</xs:simpleType>
<xs:simpleType name="MarketType">
    <xs:restriction base="xs:string">
        <xs:enumeration value="Weak" />
        <xs:enumeration value="Strong" />
    </xs:restriction>
</xs:simpleType>

当我运行XSD.exe时,输出的.cs文件不应该为我的每个简单类型都有一个xml枚举属性吗。也许我做错了什么?在.cs文件中的任何位置都看不到枚举

如果你需要更多的信息,让我知道我能提供什么

谢谢

更新:


似乎我是在使用XSD.exe创建一个数据集(/d开关),而我本应该创建一个类(/c开关)。在我设置它生成一个类之后,它工作正常。

它适合我吗?但我必须添加一个schema元素,并在ItemType中插入一个元素

<xs:schema
   elementFormDefault    ="qualified"
   targetNamespace       ="urn:Jon.Stackoverflow._2009aug.Example"
   xmlns:tns             ="urn:Jon.Stackoverflow._2009aug.Example"
   xmlns:xs              ="http://www.w3.org/2001/XMLSchema"
   >


<xs:element name="ItemList" nillable="false">
  <xs:complexType>
    <xs:sequence minOccurs="1"
                 maxOccurs="1">
      <xs:element name="Item"
                  type="tns:ItemType"
                  minOccurs="1"
                  maxOccurs="unbounded"
                  nillable="false">
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>

<xs:complexType name="ItemType">
  <xs:sequence maxOccurs="1" minOccurs="1"> 
     <xs:element type="xs:int" name="num"/>
  </xs:sequence>
  <xs:attribute name="Market"
                type="tns:MarketType"
                use="required">
  </xs:attribute>
  <xs:attribute name="Category" type="tns:CategoryType" use="required" />
</xs:complexType>

<xs:simpleType name="CategoryType">
  <xs:restriction base="xs:string">
    <xs:enumeration value="Mild" />
    <xs:enumeration value="Hot" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="MarketType">
  <xs:restriction base="xs:string">
    <xs:enumeration value="Weak" />
    <xs:enumeration value="Strong" />
  </xs:restriction>
</xs:simpleType>

</xs:schema>

它(部分)产生了这一点

//
[System.CodeDom.Compiler.GeneratedCodeAttribute(“xsd”、“2.0.50727.42”)]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace=“urn:Jon.Stackoverflow._2009aaug.Example”)]
公共枚举类型{
/// 
软弱的,
/// 
坚强的
}
/// 
[System.CodeDom.Compiler.GeneratedCodeAttribute(“xsd”、“2.0.50727.42”)]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace=“urn:Jon.Stackoverflow._2009aaug.Example”)]
公共枚举类别类型{
/// 
温和的,
/// 
热,,
}

我不知道在您的情况下会发生什么-我将您的代码复制到
enum.xsd
并在其上运行
xsd.exe
-结果如下:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.4016
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System.Xml.Serialization;

// 
// This source code was auto-generated by xsd, Version=2.0.50727.3038.
// 


/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class ItemList {

    private ItemType[] itemField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("Item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public ItemType[] Item {
        get {
            return this.itemField;
        }
        set {
            this.itemField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class ItemType {

    private MarketType marketField;

    private CategoryType categoryField;

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public MarketType Market {
        get {
            return this.marketField;
        }
        set {
            this.marketField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public CategoryType Category {
        get {
            return this.categoryField;
        }
        set {
            this.categoryField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
public enum MarketType {

    /// <remarks/>
    Weak,

    /// <remarks/>
    Strong,
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
public enum CategoryType {

    /// <remarks/>
    Mild,

    /// <remarks/>
    Hot,
}
然后我在上面运行了XSD.EXE:

xsd.exe  enum.xsd  /c
它创建了如上所示的
enum.cs
文件

您有什么版本的XSD.EXE?您使用的是什么版本的.NET


Marc

如果模式中的任何字段未使用已定义的simpleType,则其枚举将不会显示在生成的.cs文件中

类似地,如果使用它,但在类型为xs:string联合中,其枚举仍然不会显示在生成的.cs文件中


但是,如果模式包含一个字段,该字段的simpleType为原样(即不在与其他类型的联合中),则该字段将在output.cs文件中表示。

您的示例帮助我在本例中实现了该功能。以前,我生成了一个字符串类型。在我添加了一个
xmlns:tns=“mynamespace”
并在属性声明中使用
tns:
之后,我生成了一个枚举类型。
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="TheParentNode" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  ..... (inserted your code here) .......
</xs:schema> 
xsd.exe  enum.xsd  /c