0

I have an xml file from weather icons that maps a string to an html encoded font string.

I have an xml file that looks something like

<?xml version="1.0" encoding="utf-8"?>
    <resources>
      <string name="wi_owm_200">&#xf01e;</string>
    </resources>

I need a way that I can lookup easily the string wi_omw_200 and get back

&#xf01e

is there an easy way to do this in c#?

Matthew The Terrible
  • 1,589
  • 5
  • 31
  • 53

1 Answers1

2

You can use XmlNodeList

var xmlString = @"<?xml version=\"1.0\" encoding=\"utf-8\"?>
    <resources>
      <string name=\"wi_om_200w\">&#xf01e;</string>
    </resources>";

var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlString); 

var xmlNodeList = xml.SelectNodes("/resources/string[@name='wi_om_200w']");
var value = xmlNodeList.FirstOrDefault();
if (value != null)
{
    Console.WriteLine(value.InnerText);
}
d.moncada
  • 16,900
  • 5
  • 53
  • 82