Ejemplo n.º 1
0
        /// <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 XPath <see cref="System.String"/>.</param>
 /// <param name="throwException">When <code>true</code>, throw an exception for null nodes and nodes that do not parse into the specified type.</param>
 /// <param name="defaultValue">Return a boxing <see cref="System.Object"/> for “zero-length” text nodes.</param>
 /// <typeparam name="T">The type to parse from the node value.</typeparam>
 public static object GetXAttributeValueAndParse <T>(XNode set, string setQuery, bool throwException, T defaultValue)
 {
     return(XObjectUtility.GetXAttributeValueAndParse <T>(set, setQuery, throwException, defaultValue, 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));
 }
 /// <summary>
 /// Gets the <see cref="System.Xml.Linq.XDeclaration"/>.
 /// </summary>
 public static XDeclaration GetXDeclaration()
 {
     return(XObjectUtility.GetXDeclaration(XEncoding.Utf08, true));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the elements.
        /// </summary>
        /// <param name="currentElement">The current element.</param>
        /// <param name="query">The xpath query.</param>
        public static IEnumerable <XElement> GetXElements(XNode currentElement, string query)
        {
            var nodes = XObjectUtility.GetXNodes(currentElement, query);

            return(nodes.OfType <XElement>());
        }