/// <summary> /// Gets the element or attribute value of the specified element. /// </summary> /// <param name="currentNode">The current </param> /// <param name="query">The xpath query.</param> /// <param name="throwException">if set to <c>true</c> throw exception.</param> public static string GetValue(XNode currentNode, string query, bool throwException) { var node = XObjectUtility.GetXObject(currentNode, query); if (node == null) { if (throwException) { throw new ArgumentException("The XPath query returns a null node", "query"); } else { return(null); } } if (node.NodeType == System.Xml.XmlNodeType.Element) { return((node as XElement).Value); } else if (node.NodeType == System.Xml.XmlNodeType.Attribute) { return((string)XObjectUtility.GetXAttributeValue(currentNode, query, throwException)); } else { return(null); } }
/// <summary> /// Returns an object for parsing /// and adding to a list of parameters for data access. /// </summary> /// <param name="set">The <see cref="System.Xml.Linq.XNode"/></param> /// <param name="setQuery">The <see cref="System.String"/></param> /// <param name="throwException">When <code>true</code>, throw an exception for null nodes.</param> /// <param name="defaultValue">Return the specified default value for “zero-length” text nodes</param> public static string GetXAttributeValue(XNode set, string setQuery, bool throwException, string defaultValue) { return(XObjectUtility.GetXAttributeValue(set, setQuery, throwException, defaultValue, null)); }