0

How should my class look like to serialize to/from a XML like this

<root>
   <MyCollection ColDetails="val1">
      <Col_Obj>
          <Prop1>xxxx</Prop1>
          <Prop2>xxxx</Prop2>
      </ColObj>
      <Col_Obj>
          <Prop1>xxxx</Prop1>
          <Prop2>xxxx</Prop2>
      </ColObj>
   </MyCollection>
</root>

...this one -> ColDetails="val1"

or

<root>
   <MyCollection>
      <ColDetails>val1</ColDetails>
      <Col_Obj>
          <Prop1>xxxx</Prop1>
          <Prop2>xxxx</Prop2>
      </ColObj>
      <Col_Obj>
          <Prop1>xxxx</Prop1>
          <Prop2>xxxx</Prop2>
      </ColObj>
   </MyCollection>
</root>

...this one -> <ColDetails>val1</ColDetails>

C# Class

  public string ColDetails { get; set; }

  public List<Col_Obj> MyCollection { get; set; }

  public class Col_Obj
  {
      public string Prop1 { get; set; }
      public string Prop2 { get; set; }
  }   

Prefer to serialize with System.Xml.Serialization.

I can easily specify two properties as an XML attribute with value using [XmlAttribute] and [XmlText], that's half the way I assume?

MrCalvin
  • 1,675
  • 1
  • 19
  • 27
  • 2
    You can paste your XML into [Xml2Csharp](https://xmltocsharp.azurewebsites.net/) and it will generate classes for you. You've got some mismatched tags - `Col_Obj` vs `ColObj` but once I got past that it worked. – Scott Hannen Aug 02 '19 at 17:20
  • It just make one-to-one XML's without collections etc, so it not of much use, at least not for creation classes to be use for serialization of dynamic data-sets. – MrCalvin Aug 02 '19 at 20:01

0 Answers0