CSharp examples for System.Xml:XML Node
Get Double from XmlNode
using System.Globalization; using System.Security.Cryptography; using System.ComponentModel; using System.Runtime.InteropServices; using System.Collections; using System.Xml.XPath; using System.Text; using System.Xml; using System.IO;//from w w w . ja va2s . c o m using System; public class Main{ /// <summary> /// /// </summary> /// <param name="Node"></param> /// <param name="NodeName"></param> /// <returns></returns> public static double GetDouble(XmlNode Node, string NodeName) { double result = -1.0; string s = GetString(Node, NodeName).Trim(); if (s.Length > 0) { try { result = Double.Parse(s, CultureInfo.InvariantCulture); } catch (ArgumentNullException) { } catch (FormatException) { } catch (OverflowException) { } } return result; } /// <summary> /// /// </summary> /// <param name="Navigator"></param> /// <param name="XPath"></param> /// <returns></returns> public static double GetDouble(XPathNavigator Navigator, XPathExpression XPath) { double result = -1.0; string s = GetString(Navigator, XPath).Trim(); if (s.Length > 0) { try { result = Double.Parse(s, CultureInfo.InvariantCulture); } catch (ArgumentNullException) { } catch (FormatException) { } catch (OverflowException) { } } return result; } /// <summary> /// /// </summary> /// <param name="Navigator"></param> /// <param name="NodeName"></param> /// <returns></returns> public static double GetDouble(XPathNavigator Navigator, string NodeName) { double result = -1.0; string s = GetString(Navigator, NodeName).Trim(); if (s.Length > 0) { try { result = Double.Parse(s, CultureInfo.InvariantCulture); } catch (ArgumentNullException) { } catch (FormatException) { } catch (OverflowException) { } } return result; } }