tvkswamy

tvkswamy

  • NA
  • 13
  • 3.9k

Search XML with C#

Dec 19 2015 9:17 AM
Hi
 
I have an XML of this format.
 
<?xml version="1.0" encoding="utf-8"?>
<Body xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<A>
<B>
<SH>
<last_update_time>2015-02-26</last_update_time>
<D></D>
<comments>Monitor</comments>
</SH>
<SH>
<last_update_time>2015-02-27</last_update_time>
<D>YYY</D>
<comments>Printer</comments>
</SH>
</B>
</A>
</Body> 
I want to populate a list as 
 2015-02-26XXX,Monitor
 2015-02-27YYYPrinter
 
In my code (C# - Winform) I have composed as below.
 
XmlNodeList xNode = xd.SelectNodes("/Body/A/B/SH");

foreach (XmlNode xndNode in xNode)
{
string LU = xndNode["last_update_time"].InnerText;
string D = xndNode["D"].InnerText;
string Comments = xndNode["comments"].InnerText;
 
Yet, I am not able to get the desired output. Any help where I have gone wrong, please.
 

Answers (2)