Mega Code Archive

 
Categories / C# / XML
 

XPathNavigator SetTypedValue Sets the typed 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(){                    XmlReaderSettings settings = new XmlReaderSettings();       settings.Schemas.Add("http://www.domain.com/books", "domainBooks.xsd");       settings.ValidationType = ValidationType.Schema;              XmlReader reader = XmlReader.Create("domainBooks.xml", settings);       XmlDocument document = new XmlDocument();       document.Load(reader);              XPathNavigator navigator = document.CreateNavigator();              navigator.MoveToChild("bookstore", "http://www.domain.com/books");       navigator.MoveToChild("book", "http://www.domain.com/books");       navigator.MoveToChild("price", "http://www.domain.com/books");              Decimal price = 19.99M;       navigator.SetTypedValue(price);              navigator.MoveToParent();       Console.WriteLine(navigator.OuterXml);    } }