コード例 #1
0
        public HtmlNode SelectSingleNode(string xpath)
        {
            if (xpath == null)
            {
                throw new ArgumentNullException(nameof(xpath));
            }
            XPathNodeIterator xpathNodeIterator = new HtmlNodeNavigator(this.OwnerDocument, this).Select(xpath);

            if (!xpathNodeIterator.MoveNext())
            {
                return((HtmlNode)null);
            }
            return(((HtmlNodeNavigator)xpathNodeIterator.Current).CurrentNode);
        }
コード例 #2
0
        public HtmlNode SelectSingleNode(string xpath)
        {
            if (xpath == null)
            {
                throw new ArgumentNullException("xpath");
            }
            XPathNodeIterator iterator = new HtmlNodeNavigator(OwnerDocument, this).Select(xpath);

            if (!iterator.MoveNext())
            {
                return(null);
            }
            HtmlNodeNavigator current = (HtmlNodeNavigator)iterator.Current;

            return(current.CurrentNode);
        }
コード例 #3
0
        public HtmlNodeCollection SelectNodes(string xpath)
        {
            HtmlNodeCollection nodes    = new HtmlNodeCollection(null);
            XPathNodeIterator  iterator = new HtmlNodeNavigator(OwnerDocument, this).Select(xpath);

            while (iterator.MoveNext())
            {
                HtmlNodeNavigator current = (HtmlNodeNavigator)iterator.Current;
                nodes.Add(current.CurrentNode);
            }
            if (nodes.Count == 0)
            {
                return(null);
            }
            return(nodes);
        }
コード例 #4
0
        public HtmlNodeCollection SelectNodes(string xpath)
        {
            HtmlNodeCollection htmlNodeCollection = new HtmlNodeCollection((HtmlNode)null);
            XPathNodeIterator  xpathNodeIterator  = new HtmlNodeNavigator(this.OwnerDocument, this).Select(xpath);

            while (xpathNodeIterator.MoveNext())
            {
                HtmlNodeNavigator current = (HtmlNodeNavigator)xpathNodeIterator.Current;
                htmlNodeCollection.Add(current.CurrentNode);
            }

            if (htmlNodeCollection.Count == 0)
            {
                return((HtmlNodeCollection)null);
            }
            return(htmlNodeCollection);
        }
コード例 #5
0
 /// <summary>
 /// Selects the first XmlNode that matches the XPath expression.
 /// 
 /// </summary>
 /// <param name="xpath">The XPath expression. May not be null.</param>
 /// <returns>
 /// The first <see cref="T:HtmlAgilityPack.HtmlNode"/> that matches the XPath query or a null reference if no matching node was found.
 /// </returns>
 public HtmlNode SelectSingleNode(string xpath)
 {
   if (xpath == null)
     throw new ArgumentNullException("xpath");
   XPathNodeIterator xpathNodeIterator = new HtmlNodeNavigator(this.OwnerDocument, this).Select(xpath);
   if (!xpathNodeIterator.MoveNext())
     return (HtmlNode) null;
   return ((HtmlNodeNavigator) xpathNodeIterator.Current).CurrentNode;
 }
コード例 #6
0
 /// <summary>
 /// Selects a list of nodes matching the <see cref="P:HtmlAgilityPack.HtmlNode.XPath"/> expression.
 /// 
 /// </summary>
 /// <param name="xpath">The XPath expression.</param>
 /// <returns>
 /// An <see cref="T:HtmlAgilityPack.HtmlNodeCollection"/> containing a collection of nodes matching the <see cref="P:HtmlAgilityPack.HtmlNode.XPath"/> query, or <c>null</c> if no node matched the XPath expression.
 /// </returns>
 public HtmlNodeCollection SelectNodes(string xpath)
 {
   HtmlNodeCollection htmlNodeCollection = new HtmlNodeCollection((HtmlNode) null);
   XPathNodeIterator xpathNodeIterator = new HtmlNodeNavigator(this.OwnerDocument, this).Select(xpath);
   while (xpathNodeIterator.MoveNext())
   {
     HtmlNodeNavigator htmlNodeNavigator = (HtmlNodeNavigator) xpathNodeIterator.Current;
     htmlNodeCollection.Add(htmlNodeNavigator.CurrentNode);
   }
   if (htmlNodeCollection.Count == 0)
     return (HtmlNodeCollection) null;
   return htmlNodeCollection;
 }