Keyboard Shortcuts
Likes
Search
XML in vs2008
#simplsharp
I'm working with a device that returns an XML payload upon query.? I have this device working perfectly on 4 series BUT now I need to make this backwards compatible with 3 series (using vs2008 and CF 3.5) because of the processor shortage. I can't figure out what the best method is to manage and then deserialize the XML properly. What I'm doing on 4 series is deserializing using another class I created which doesn't exist in the CF 3.5 sandbox. Example Code on 4 Series: using (StreamReader sr = new StreamReader(s)) //"s" is my response stream from a webrequest
? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? var xmlData = sr.ReadToEnd();? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xmlData)))
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? XmlSerializer serializer = new XmlSerializer(typeof(ExampleDataModel), new XmlRootAttribute("data"));
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ExampleDataModel?data = (ExampleDataModel) serializer.Deserialize(ms);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // do other stuff with my data ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
Example of the XML return from my device <?xml version="1.0" encoding="UTF-8" ?>
<data serial="0x4a">
? ? <ts>1667580367</ts>
? ? <r t="P" n="Name2" did="2">
? ? ? ? <v>9215522798</v>
? ? ? ? <i>0</i>
? ? </r>
? ? <r t="P" n="Name3" did="3">
? ? ? ? <v>6551567803</v>
? ? ? ? <i>0</i>
? ? </r>
? ? <r t="P" n="Name15" did="15">
? ? ? ? <v>-6025876766</v>
? ? ? ? <i>6</i>
? ? </r>
? ? <r t="P" n="Name4" did="4">
? ? ? ? <v>-6372792531</v>
? ? ? ? <i>6</i>
? ? </r>
? ? <r t="P" n="Name5" did="5">
? ? ? ? <v>81964060</v>
? ? ? ? <i>-5</i>
? ? </r>
? ? <r t="P" n="Name6" did="6">
? ? ? ? <v>-664628793</v>
? ? ? ? <i>-9</i>
? ? </r>
? ? <r t="P" n="Name7" did="7">
? ? ? ? <v>-598632391</v>
? ? ? ? <i>-10</i>
? ? </r>
? ? <r t="P" n="Name9" did="9">
? ? ? ? <v>-7313215090</v>
? ? ? ? <i>-87</i>
? ? </r>
? ? <r t="P" n="Name10" did="10">
? ? ? ? <v>-2644948853</v>
? ? ? ? <i>-90</i>
? ? </r>
? ? <r t="P" n="Name11" did="11">
? ? ? ? <v>-1432490</v>
? ? ? ? <i>-3</i>
? ? </r>
? ? <r t="P" n="Name12" did="12">
? ? ? ? <v>-6767026506</v>
? ? ? ? <i>-444</i>
? ? </r>
? ? <r t="P" n="Name13" did="13">
? ? ? ? <v>-4801078066</v>
? ? ? ? <i>-228</i>
? ? </r>
? ? <r t="P" n="Name8" did="8">
? ? ? ? <v>-2331104692</v>
? ? ? ? <i>-104</i>
? ? </r>
? ? <r t="P" n="Name0" did="0">
? ? ? ? <v>40365273148</v>
? ? ? ? <i>747</i>
? ? </r>
? ? <r t="P" n="Name1" did="1">
? ? ? ? <v>36484275778</v>
? ? ? ? <i>569</i>
? ? </r>
</data>
Any help is greatly appreciated as I'm currently stuck. |
¿ªÔÆÌåÓýI was able to use XDocument on 3 series using Crestron.SimplSharp.CrestronXmlLinq; XDocument xdoc = XDocument.Parse(xmlString);
|
¿ªÔÆÌåÓýHere is part of the code I wrote for reading xml data from a file for a module I have that tracks the angle and elevation of the sun, compares that with data for each window, and automates the operation of shades based on whether the sun is shining through a window or not. Hope this helps ??????? private bool Read_XML_Data(string xml_data_file, string
path) On 11/8/2022 12:54 PM, Bruce Levy via
groups.io wrote:
|