.net - Deserializing sequence of nested elements -


i'm stumped on how deserialize following xml entities i've created:

 <values totalcount="576">       <version>3</version>       <item>          <datetime>2/22/2016 8:35:00 pm - 8:40:00 pm</datetime>          <value channel="outside" channelid="4">10.0000</value>       </item>       <item>          <datetime>2/22/2016 8:40:00 pm - 8:45:00 pm</datetime>          <value channel="inside" channelid="2"/>       </item>    </values> 

these classes i've used. when deserialize, valueitems list created correct number of items , correct totalcount , version values but each valueitem has default values members instead of expected values:

public class values     {         [xmlattribute(attributename = "totalcount")]         public int totalcount { get; set; }          [xmlelement(elementname = "version")]         public string version { get; set; }          [xmlelement(elementname ="item")]         public list<valueitem> valueitems { get; set; }     }    public class valueitem     {         [xmlelement(elementname = "datetime")]         public string datetime { get; set; }          [xmlelement(elementname="value")]         public sensorvalue value { get; set; }     }  public class sensorvalue     {         [xmlattribute(attributename = "channel")]         public string channel { get; set; }          [xmlattribute(attributename = "channelid")]         public string channelid { get; set; }          public string value { get; set; }     } 

i've tried decorating valueitems xmlarrayitem("item"). i've tried xmlarrayitem along xmlarray. i've tried decorating valueitem class xmltype("item").

any ideas? msdn docs on using xmlattributes aren't comprehensive.

you can use visual studio's built in xml classes xml:

/// <remarks/> [system.xml.serialization.xmltypeattribute(anonymoustype=true)] [system.xml.serialization.xmlrootattribute(namespace="", isnullable=false)] public partial class values {      private byte versionfield;      private valuesitem[] itemfield;      private ushort totalcountfield;      /// <remarks/>     public byte version {         {             return this.versionfield;         }         set {             this.versionfield = value;         }     }      /// <remarks/>     [system.xml.serialization.xmlelementattribute("item")]     public valuesitem[] item {         {             return this.itemfield;         }         set {             this.itemfield = value;         }     }      /// <remarks/>     [system.xml.serialization.xmlattributeattribute()]     public ushort totalcount {         {             return this.totalcountfield;         }         set {             this.totalcountfield = value;         }     } }  /// <remarks/> [system.xml.serialization.xmltypeattribute(anonymoustype=true)] public partial class valuesitem {      private string datetimefield;      private valuesitemvalue valuefield;      /// <remarks/>     public string datetime {         {             return this.datetimefield;         }         set {             this.datetimefield = value;         }     }      /// <remarks/>     public valuesitemvalue value {         {             return this.valuefield;         }         set {             this.valuefield = value;         }     } }  /// <remarks/> [system.xml.serialization.xmltypeattribute(anonymoustype=true)] public partial class valuesitemvalue {      private string channelfield;      private byte channelidfield;      private string valuefield;      /// <remarks/>     [system.xml.serialization.xmlattributeattribute()]     public string channel {         {             return this.channelfield;         }         set {             this.channelfield = value;         }     }      /// <remarks/>     [system.xml.serialization.xmlattributeattribute()]     public byte channelid {         {             return this.channelidfield;         }         set {             this.channelidfield = value;         }     }      /// <remarks/>     [system.xml.serialization.xmltextattribute()]     public string value {         {             return this.valuefield;         }         set {             this.valuefield = value;         }     } } 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -