I have the following method which loops through the <desc> node in an xml file to find if it matches the parameter "msg".
What I need to do is ,once found retrieve the <code> from the xml. How do I do that?
static string getCode(string msg)
{
string filename = @"C:\temp\errors.xml";
string xmlCode="";
XmlDocument doc = new XmlDocument();
doc.Load(filename);
XmlNodeList nodes = doc.SelectNodes("/edt/ce/desc");
foreach (XmlNode node in nodes)
{
if (node.InnerText.Trim().Equals(msg))
xmlCode = "Found"; //should be the <code> associated to the matching <desc>
else
xmlCode = "Not found";
}
msg = xmlCode;
return msg;
}
This is errors.xml
<edt name="errors">
<ce>
<code>1111</code>
<desc>Not here</desc>
</ce>
<ce>
<code>2222</code>
<desc>Invalid Input </desc>
</ce>
</edt>
Open in new window