c# - Serialize List Without an Extra Element -


this question has answer here:

i can generate following xml document i'm having trouble version attribute on 'iskeyvaluelist'element. using xmlserializer. should note xml being passed api requires exact structure follows.

<userdata>   <iskeyvaluelist  version="1.00">      <item type="string" key="ageofdependents">8,6,1<item/>      <item type="boolean" key="securitiesinposession"> true </item>      <item type="boolean" key="securitiesowners"> true </item>   </iskeyvaluelist> </userdata>  

i have read several stack overflow bounties have learned add version attribute list had move list class. following generates structure above adds element want avoid.

c#

userdata newuserdata = new userdata(); newuserdata.iskeyvaluelist = new dataproperties(); newuserdata.iskeyvaluelist.items = new list<item>() {    new item()    {        type = "string",        key = "ageofdependents",        //add data form       value = string.join(",", application.applicants[0].ageofdependants)       },     new item(){ type = "boolean", key = "securitiesinpossession", value = "true" }     };  newclientdetails.userdata = newuserdata;  //pass object serializer here 

model

public class userdata {     public dataproperties iskeyvaluelist { get; set; } }  public class dataproperties {     [xmlattribute("version")]     public string version { get; set; }     public list<item> items { get; set; }      public dataproperties()     {         version = "1.00";     } }  public class item {     [xmlattribute("type")]     public string type { get; set; }     [xmlattribute("key")]     public string key { get; set; }     [xmltext]     public string value { get; set; } } 

current output

enter image description here

however add extra, unwanted element (highlighted above) xml document. there way can remove element configuring model i'd rather avoid setting custom serializers etc.

add attribute [xmlelement("item")] dataproperties.items property.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -