CSharp examples for System.Xml:XML Node
Extract Numeric value from XmlNode
using System.Diagnostics; using System.Xml; using System.Collections.Generic; using System;/*ww w. java2s . co m*/ public class Main{ public static T ExtractNumeric<T>(XmlNode node, string nodeName, T defualtVal, bool isMust) { T result = defualtVal; if (node == null || !node.HasChildNodes || node.SelectSingleNode(nodeName) == null) { if (isMust) { Debug.Assert(false, "ExtactString Error!"); } return result; } XmlNode childNode = node.SelectSingleNode(nodeName); string nodeText = childNode.InnerText; if (string.IsNullOrEmpty(nodeText)) { if (isMust) { Debug.Assert(false, "ExtactString Error!"); } } else { result = (T)Convert.ChangeType(nodeText, typeof(T)); } return result; } }