XPath expression help
I have the following xml file and need the XPath expression to select the action element with the name "revision1" from the version element with the number 1.
Thanks,
David
<?xml version="1.0" standalone="yes"?>
<configuration>
<ConfigOpt>
<version number="1">
<action type="add" name="revision1" value="VALUE1"/>
<action type="change" name="revision2" value="VALUE2"/>
<action type="delete" name="revision3"/>
</version>
<version number="2">
<action type="delete" name="revision1"/>
<action type="change" name="revision2" value="VALUE 2 NEW VALUE"/>
<action type="add" name="revision3" value="VALUE3"/>
</version>
</ConfigOpt>
</configuration>
[873 byte] By [
dbradley] at [2007-11-11 11:59:03]

# 1 Re: XPath expression help
using System.Xml.XPath;
XPathDocument doc = new XPathDocument(@"d:\path\file.xml");
XPathNavigator nav = doc.CreateNavigator();
XPathNavigator node = nav.SelectSingleNode("//version[@number='1']/action[@name='revision1']");
Console.WriteLine(node.OuterXml);
Console.WriteLine("type = {0}", node.GetAttribute("type", ""));
Console.WriteLine("value = {0}", node.GetAttribute("value", ""));