XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("data.xml"); XmlNodeList nodes = xmlDoc.SelectNodes("//book/title"); foreach(XmlNode node in nodes) { Console.WriteLine(node.InnerText); }
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("data.xml"); XmlNode node = xmlDoc.SelectSingleNode("//book[title='Programming in C#']/price"); node.InnerText = "49.99"; xmlDoc.Save("data.xml");In this example, we load an XML file using the XmlDocument class and then use the SelectSingleNode() method to retrieve a single node that matches a particular XPath expression. We then update the inner text of the node and save the changes back to the original XML file. The package library for the System.Xml namespace is the .NET Framework Class Library.