Find XML node in C# ignore the rest

reddragonpoker

New Member
I have an very ugly APP done by me that reads serial port from my PC, the device attached to this serial port sends XML Data to this APP... My app reads the XML data to a string and looks for variable in node \[code\]<watts>\[/code\], but once a while the Device sends different XML Data(historic data), and my app with that information it crashes because it doesn't find the node \[code\]<watts>\[/code\]. I only want to check if the node is there and ignore the incorrect data. The data comes from the Serial Port to a String called XMLData...Correct Data: \[code\]<msg> <src>CC128-v1.34</src> <dsb>00030</dsb> <time>21:01:59</time> <tmpr>18.4</tmpr> <sensor>0</sensor> <id>00077</id> <type>1</type> <ch1> <watts>00366</watts> </ch1></msg>\[/code\]Incorrect data: \[code\]<msg> <src>CC128-v1.34</src> <dsb>00030</dsb> <time>21:02:00</time> <hist> <dsw>00030</dsw> <type>1</type> <units>kwhr</units> <data> <sensor>0</sensor> <h650>0.856</h650> <h648>1.418</h648> <h646>0.765</h646> <h644>0.742</h644> </data> <data> <sensor>1</sensor> <h650>0.000</h650> <h648>0.000</h648> <h646>0.000</h646> <h644>0.000</h644> </data> <data> <sensor>2</sensor> <h650>0.000</h650> <h648>0.000</h648> <h646>0.000</h646> <h644>0.000</h644> </data> </hist></msg>\[/code\]
 
Back
Top