问题
I am trying to generate C# code from an XSD using xsd.exe
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[]
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?
Question Update:
Or is xsd.exe bugged?
回答1:
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.
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.
<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>
来源:https://stackoverflow.com/questions/1165999/problem-with-code-generated-by-xsd-exe-sequence-of-elements-is-generated-as-an