简体   繁体   English

XSD.EXE生成的代码的问题:元素序列生成为数组

[英]Problem with Code Generated by XSD.EXE: Sequence of Elements is Generated as an Array

I am trying to generate C# code from an XSD using xsd.exe 我正在尝试使用xsd.exe从XSD生成C#代码

Here is a snippet of the problematic area 这是有问题的区域的片段

<xs:element name="EmailConfiguration" minOccurs="1" maxOccurs="1">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="DefaultSendToAddressCollection" minOccurs="0" maxOccurs="1">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="EmailAddress" type="xs:string" minOccurs="1" maxOccurs="unbounded" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>

        </xs:sequence>
      </xs:complexType>
    </xs:element>

Currently DefaultSendToAddressCollection is being generated as a string[] 当前,DefaultSendToAddressCollection正在作为字符串生成[]

How can I change the xsd, so that it is generated as a strong type, and email addresses as a collection to the strong type? 如何更改xsd,以便将其生成为强类型,并将电子邮件地址作为强类型的集合?

Question Update: 问题更新:

Or is xsd.exe bugged? 还是xsd.exe错误?

You've specified EmailAddress to be of type xs:string instead of a complex type - therefore, DefaultSendToAddressCollection is an array of strings, instead of a collection of objects. 您已将EmailAddress指定为xs:string类型,而不是复杂类型-因此,DefaultSendToAddressCollection是字符串数组,而不是对象集合。

If you change EmailAddress to be a complex type, and give it an xs:attribute of type xs:string to store the address to, you will end up with a collection of EmailAddress objects. 如果将EmailAddress更改为复杂类型,并为其提供xs:attribute xs:string类型的xs:attribute来存储地址,则最终将得到一系列EmailAddress对象。

<xs:element name="EmailConfiguration" minOccurs="1" maxOccurs="1">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="DefaultSendToAddressCollection" minOccurs="0" maxOccurs="1">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="EmailAddress" minOccurs="1" maxOccurs="unbounded">
                  <xs:complexType>
                    <xs:attribute name="Address" type="xs:string" />
                  </xs:complexType>
                </xs:element>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:complexType>
    </xs:element>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM