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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.