tags:

views:

500

answers:

1

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

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>
womp
Basically What I want is a collection of emailAddresses or string[]EmailAddressWhat I am getting is string[] DefaultSendToAddressCollection and the generated code has no collection of email addresses.
JL
Also if you look at the xsd, it seems Email is a complex type:<xs:complexType> <xs:sequence> <xs:element name="EmailAddress" type="xs:string" minOccurs="1" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType>
JL
Better still can you please provide an example...
JL
No, DefaultSendToAddressCollection is the complex type. The element tag for EmailAddress says type="xs:string" - it's a simple type. I'll whip up an example.
womp
Remember that if you make a sequence consisting of simple types, it comes out as an array, because really there is no point in having a collection of simple types. It seems like if all you are storing is just one string, the email address, than having DefaultSendToAddressCollection as a string array should work fine for you.
womp
What I've specified in my example will make DefaultSendToAddressCollection into a collection of "EmailAddress" objects, which have one string property, "Address".
womp
perfect, thank you so much, it was driving me nuts
JL
Only problem is getting the exception the name attribute is not supported in this context... for the attribute
JL
JL - the "Name" property on EmailAddress should actually be "name". Lower case N. Sorry about that.I think the attribute should be fine.
womp
cool stuff, fixed now :)
JL