0

I have the following:

[XmlArrayItem("ScheduleClassic")]
public ScheduleCollection Classes { get; set; }

Which produces the following:

<Classes>
  <ScheduleClassic>
      list of elements...
  </ScheduleClassic>
  <ScheduleClassic>
      list of elements...
  </ScheduleClassic>
</Classes

What I want to produce is the following with a number appended to each one for a count.

<Classes>
  <ScheduleClassic1>
      list of elements...
  </ScheduleClassic>
  <ScheduleClassic2>
      list of elements...
  </ScheduleClassic2>
</Classes>
Noam Hacker
  • 4,671
  • 7
  • 34
  • 55
  • So you want something to serialize the index of each item in the list, along with the item? – SneakyTactician Aug 11 '17 at 14:31
  • 2
    Why? If all ScheduleClassics are of the same element type, why are you renaming the elements to be something different? – mason Aug 11 '17 at 14:32
  • The data is being sent to a third party and that is the structure that they are asking for. – Joe Phillips Aug 11 '17 at 14:34
  • 1
    You could just add an attribute with an index if you really needed the numerical representation of the index. – maccettura Aug 11 '17 at 14:34
  • I suppose you should implement `IXmlSerializable` for your `scheduleClassic`-class to write the number of the element also. Another way would be to add an attribute to the xml-tag, which looks like this: `...`. – MakePeaceGreatAgain Aug 11 '17 at 14:36
  • I don't really recommend doing this since it makes it difficult to create an [XSD](https://en.wikipedia.org/wiki/XML_Schema_(W3C)) for your type. That being said, does [this](https://stackoverflow.com/a/37262084/3744182) do what you want? Sample [fiddle](https://dotnetfiddle.net/PCC6YI). – dbc Aug 12 '17 at 04:46

0 Answers0