troubleshooting Question

Deserialize XML to C#

Avatar of wint100
wint100Flag for United Kingdom of Great Britain and Northern Ireland asked on
XML.NET ProgrammingC#
6 Comments1 Solution130 ViewsLast Modified:
I'm trying to deserialize an XML reponse into a C# class but due t the complexity of the XML and the re-use of names, Restsharp only gets the top level elements:

The elements I'm ooking to get are the Collection types where nodeType="System", I need a List of all of these that include the Objects for each collection and also the 'Real' objects that are within the Objects elements.

So, the result would be a list of Collections (e.g. Bedroom, Kitchen). Each item would have an Objects Collection, that contained a list of Objects (e.g. "TEMP_SP", "TEMP")

I'm using Restsharp but need the Class structure to handle full deserialization of the XML response.

<?xml version="1.0" encoding="UTF-8"?>

-<Collection xmlns="http://bacnet.org/csml/1.2" name="Test">


-<Collection name="Bedroom">


-<Struct name="Bedroom" nodeType="System">

<String name="location" value=""/>

<String name="address" value=""/>

<String name="description" value=""/>

<String name="template" value="vstat.xml"/>


-<Struct name="Objects">

<Real name="TEMP_SP" value="23" physical="/.bacnet/Birchall HQ/1300/analog-value,10" description="" displayName="GB Occupied Space Setpoint"/>

<Real name="TEMP" value="15.8905" physical="/.bacnet/Birchall HQ/1300/analog-input,2" description="" displayName="Conference Room Temp"/>

</Struct>

</Struct>


-<Struct name="Default System Dashboard" nodeType="Other">

<Enumerated name="Type" value="System"/>

<Enumerated name="Layout" value="2"/>


-<Collection name="Widgets">


-<Struct name="763631f4-f701-11e3-8d86-d4bed9a91498">

<String name="Type" value="Alarm Summary"/>

</Struct>


-<Struct name="764769bc-f701-11e3-8d86-d4bed9a91498">

<String name="Type" value="Point List"/>

</Struct>


-<Struct name="764769d6-f701-11e3-8d86-d4bed9a91498">

<String name="Type" value="Alarm List"/>

</Struct>

</Collection>

</Struct>

</Collection>


-<Collection name="Kitchen">


-<Struct name="Kitchen" nodeType="System">

<String name="location" value=""/>

<String name="address" value=""/>

<String name="description" value=""/>

<String name="template" value="vstat.xml"/>

-<Struct name="Objects">

<Real name="TEMP_SP" value="23" physical="/.bacnet/Birchall HQ/1300/analog-value,10" description="" displayName="GB Occupied Space Setpoint"/>

<Real name="TEMP" value="15.8905" physical="/.bacnet/Birchall HQ/1300/analog-input,2" description="" displayName="Conference Room Temp"/>

</Struct>


-<Struct name="Default System Dashboard" nodeType="Other">

<Enumerated name="Type" value="System"/>

<Enumerated name="Layout" value="2"/>


-<Collection name="Widgets">


-<Struct name="763631f4-f701-11e3-8d86-d4bed9a91498">

<String name="Type" value="Alarm Summary"/>

</Struct>


-<Struct name="764769bc-f701-11e3-8d86-d4bed9a91498">

<String name="Type" value="Point List"/>

</Struct>


-<Struct name="764769d6-f701-11e3-8d86-d4bed9a91498">

<String name="Type" value="Alarm List"/>

</Struct>

</Collection>

</Struct>

</Collection>

</Collection>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros