Search code examples
c#.net.net-2.0xmldocument

XmlDocument query taking two values


How I can make following query

If I have XmlDocument and it may have following xml

<EquipmentParameterModified dateTime="2011-04-06T12:03:10.00+01:00" parameter="ExtApp">
  <Extensions ParameterId="External App Interface" FromParameterValue="" ToParameterValue="DISABLED"/>
</EquipmentParameterModified>

How I can check that I have EquipmentParameterModified and take values of ParameterId and ToParameterValue

Thanks for help.


Solution

  • XmlDocument xmldoc = new XmlDocument();
    xmldoc.Load(new StringReader(xmlstr));
    XmlNode node = xmldoc.GetElementsByTagName("Extensions").Item(0);
    string id =  node.Attributes["ParameterId"].Value;
    string val = node.Attributes["ToParameterValue"].Value;