Mega Code Archive

 
Categories / C# / XML
 

XPathNavigator SetValue Sets the value of the current node

using System; using System.Linq; using System.Xml; using System.Xml.Linq; using System.Collections; using System.Collections.Generic; using System.Xml.XPath; public class MainClass{    public static void Main(){                    XmlDocument document = new XmlDocument();       document.Load("domainBooks.xml");       XPathNavigator navigator = document.CreateNavigator();              XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable);       manager.AddNamespace("bk", "http://www.domain.com/books");              foreach (XPathNavigator nav in navigator.Select("//bk:price", manager))       {           if (nav.Value == "11.99")           {               nav.SetValue("12.99");           }       }              Console.WriteLine(navigator.OuterXml);    } }