1

How do I go about deserializing a collection of Xml elements (all with the same element name, but with specific attributes) to an object?

Here's a snippet of the Xml:

<mibscalar name="lotOccupiedPct" link="http://localhost:8080/v1/mib/objs/lotOccupiedPct?type=xml">
<data index="1" value="0" counter="0"/>
</mibscalar>
<mibscalar name="gateStatusCloseThreshold" type="readonly" link="http://localhost:8080/v1/mib/objs/gateStatusCloseThreshold?type=xml">
<data index="1" value="90" counter="0"/>
</mibscalar>
<mibscalar name="gateStatusOpenThreshold" type="readonly" link="http://localhost:8080/v1/mib/objs/gateStatusOpenThreshold?type=xml">
<data index="1" value="70" counter="0"/>
</mibscalar>

And the corresponding properties in my class (in order):

public int CurrentOccupancyPercentage { get; set; }
public int CloseThresholdPercentage { get; set; }
public int OpenThresholdPercentage { get; set; }

I'm assuming there are some attributes I can add to the properties that can handle this scenario?

Thanks in advance.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Sonny Boy
  • 7,848
  • 18
  • 76
  • 104

1 Answers1

1

You need to build a class with properties using XmlAttribute and XmlElement. It will allow you to serialize and deserialize to a XML file.

Here is an example Serialize Property as Xml Attribute in Element.

Community
  • 1
  • 1