1

I'm using an .xsd schema like this

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Scene">
<xs:complexType>
  <xs:sequence>
    <xs:element name="SceneName" type="xs:string" minOccurs="0" maxOccurs="1" />
    <xs:element name="PlayerName" type="xs:string" minOccurs="0" maxOccurs="1" />  
    <xs:element name="Button" minOccurs="0" maxOccurs="unbounded" >
      <xs:complexType>
        <xs:sequence>
          <xs:element name="ButtonText" type="xs:string" minOccurs="0" maxOccurs="1" />
          <xs:element name="NextScene" type="xs:string" minOccurs="0" maxOccurs="1" />
        </xs:sequence>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
 </xs:complexType>
</xs:element>
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
 <xs:complexType>
  <xs:choice minOccurs="0" maxOccurs="unbounded">
    <xs:element ref="Scene" />
  </xs:choice>
  </xs:complexType>
 </xs:element>
</xs:schema>

This was autogenerated by Visual Studios xsd.exe. Then i use xsd2code to make it to a .designer.cs file. I set xsd2code so it creates serializers and makes complex type structures to arrays.

xsd2codeWindow

Now i deserialzie an xml and create my scenefile, my subobjekts like playername are all correct, even if they have subobjects as long as they are set maxoccurence=1 and minoccurence=0. Exept for my Arrays like Button in the aboce example, I thought i would get an array like this: scene.Button[i].Buttontext. Well, which i don't get. I only get i don't know what thats why i have an screenshot here.

Failpart

and he throws an IndoexoutofRange Error. So what did i do wrong?

Btw here my example.xml

<?xml version="1.0" encoding="utf-8"?>
 <Scene>
  <SceneName>SceneName1</SceneName>
   <PlayerName>PlayerName1</PlayerName>
   <Button>
    <ButtonText>ButtonText1</ButtonText>
    <NextScene>NextScene1</NextScene>
   </Button>
Master117
  • 660
  • 6
  • 21

1 Answers1

3

Found it, needed.to set GenerateXMLAttributes true;

Master117
  • 660
  • 6
  • 21
  • This did not work for me. Anyone else with a suggestion on this? – Spiralis Mar 08 '15 at 22:01
  • @Spiralis use an XMLSerializer, by now I learned that serializers are a better approach. Create yor object in code and Serialize it. – Master117 Mar 09 '15 at 07:23
  • I just found out why I think. If the collection has no attributes and just wraps a sequence it creates arrays. If however the collection-element has any attributes defined, then the collection needs to be a class in it's own, to cater for the extra properties generated. So, in my case this really was as "expected", I somehow just didn't see it when this happened. – Spiralis May 06 '15 at 01:40