XSD.exe /dataset 未从我的 xsd 文件创建枚举

发布于 2024-08-01 22:24:17 字数 1670 浏览 2 评论 0原文

我创建了一个 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 开关)。 当我设置它生成一个类后,它工作正常。

I have created an XSD and have run XSD.exe on top of that .xsd file. It seems that my simple types that are restricted to enumeration values are not being generated as enums in the outputted .cs file.

For example, my xsd looks like this:

<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>

When I run XSD.exe shouldn't the outputted .cs file have an xml enum attribute for each of my simple types? This link says that it should. Maybe I am doing something wrong? No where in my .cs file do I see an enum.

If you need any more information, let me know what I can provide.

Thanks.

UPDATE:

It seems that I was using XSD.exe to create a dataset (/d switch), when I should have been creating a class (/c switch). After I set it generate a class, it worked correctly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

呆橘 2024-08-08 22:24:17

如果架构中的任何字段均未使用已定义的 simpleType,则其枚举 将不会在生成的 .cs 文件中表示。

同样,如果使用它,但在类型为 xs:stringunion 中,则其 enum 仍然不会在生成的 .cs 文件中表示。

但是,如果模式包含按原样使用 simpleType 的字段(即不在具有其他类型的 union 中),则它将在输出 .cs 文件中表示。

If a defined simpleType is not used by any field in the schema, its enum will not be represented in the resulting .cs file.

Likewise, if it IS used but in a union with the type xs:string, its enum is still not represented in the resulting .cs file.

If, however, the schema contains a field with the simpleType as is (i.e. not in a union with some other type), it will be represented in the output .cs file.

一世旳自豪 2024-08-08 22:24:17

这个对我有用? 但我必须添加一个架构元素,并在 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>

它生成这个(部分)

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:Jon.Stackoverflow._2009aug.Example")]
public enum MarketType {

    /// <remarks/>
    Weak,

    /// <remarks/>
    Strong,
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:Jon.Stackoverflow._2009aug.Example")]
public enum CategoryType {

    /// <remarks/>
    Mild,

    /// <remarks/>
    Hot,
}

it works for me? But I had to add in a schema element, and insert an element inside 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>

It generates this (in part)

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:Jon.Stackoverflow._2009aug.Example")]
public enum MarketType {

    /// <remarks/>
    Weak,

    /// <remarks/>
    Strong,
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:Jon.Stackoverflow._2009aug.Example")]
public enum CategoryType {

    /// <remarks/>
    Mild,

    /// <remarks/>
    Hot,
}
梦行七里 2024-08-08 22:24:17

我不知道你的情况会发生什么 - 我将你的代码复制到 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,
}

我肯定得到了两个枚举CategoryTypeMarketType

我所做的就是将您的 XSD 代码放入 标记中:

<?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:

xsd.exe  enum.xsd  /c

这创建了所示的 enum.cs 文件多于。

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

马克

I don't know what happens in your case - I copied your code into enum.xsd and ran xsd.exe on it - here's the result:

//------------------------------------------------------------------------------
// <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,
}

I definitely got the two enums CategoryType and MarketType.

All I did was put your XSD code into a <xsl:schema> tag:

<?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> 

and then I ran XSD.EXE on it:

xsd.exe  enum.xsd  /c

which created the enum.cs file shown above.

What version of XSD.EXE do you have? What version of .NET are you using?

Marc

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文