简体   繁体   中英

Deserialize multiple XML elements have same name

i have an XML form look like this:

<Myset>
   <element>1A</element>
   <element>2B</element>
   <element>3C</element>
   <element>AB</element>
   ..........
   <element>AA</element>

What should structure class, variables should i use to deserialize it. I want to read and update value of each element. I have try this, but it doesn't work:

public class Myset
{
  public List<string> element {get; set;}
  // or public string[] element { get; set; }
}

XmlElementAttribute will allow you specify element name.

public class case_id_list
{
  [XmlElement("case_id")]
  public List<string> case_id {get; set;}
}

You should use this service . It converts your xml structure to valid c# model structure. It's a very useful tool.

*In case you ever want to convert your JSON to C# this is another useful service .

Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM