Mega Code Archive

 
Categories / C# / XML
 

XPathNavigator ValueAsBoolean Gets the current nodes value as a Boolean

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()     {         XPathDocument document = new XPathDocument("valueas.xml");         XPathNavigator navigator = document.CreateNavigator();         navigator.MoveToChild("root", "");         navigator.MoveToChild("booleanElement", "");         bool booleanValue = navigator.ValueAsBoolean;         Console.WriteLine(navigator.LocalName + ": " + booleanValue);         navigator.MoveToNext("dateTimeElement", "");         DateTime dateTimeValue = navigator.ValueAsDateTime;         Console.WriteLine(navigator.LocalName + ": " + dateTimeValue);         navigator.MoveToNext("numberElement", "");         Double doubleValue = navigator.ValueAsDouble;         Int32 int32Value = navigator.ValueAsInt;         Int64 int64Value = navigator.ValueAsLong;         Console.WriteLine(navigator.LocalName + ": " + doubleValue);         Console.WriteLine(navigator.LocalName + ": " + int32Value);         Console.WriteLine(navigator.LocalName + ": " + int64Value);     } }