/// <summary> /// Run xpath from html or node /// </summary> public List<List<KeyValuePair<string, object>>> run(HtmlNode node) { Factory.Instance.iInfo(string.Format("Running xpathCollection id : {0}", rule.id)); HtmlNodeCollection nodes = new HtmlNodeCollection(node); HtmlNodeCollection n2 = node.SelectNodes(rule.xpath); if (n2 != null) { foreach (HtmlNode n in n2) nodes.Add(n); } //run if (node != null) { foreach (HtmlNode n in nodes) { List<KeyValuePair<string, object>> last_val = null; if (rule.xpathSingle != null) { XPathSingle xs = new XPathSingle(rule.xpathSingle, last_val); last_val = (List<KeyValuePair<string, object>>)xs.Run(n); res.Add(last_val); } } } return res; }
/// <summary> /// Selects a list of nodes matching the <see cref="XPath"/> expression. /// </summary> /// <param name="xpath">The XPath expression.</param> /// <returns>An <see cref="HtmlNodeCollection"/> containing a collection of nodes matching the <see cref="XPath"/> query, or <c>null</c> if no node matched the XPath expression.</returns> public HtmlNodeCollection SelectNodes(string xpath) { var list = new HtmlNodeCollection(null); var nav = new HtmlNodeNavigator(OwnerDocument, this); var it = nav.Select(xpath); while (it.MoveNext()) { var n = (HtmlNodeNavigator)it.Current; list.Add(n.CurrentNode); } return list.Count == 0 ? null : list; }
/// <summary> /// Selects a list of nodes matching the <see cref="XPath"/> expression. /// </summary> /// <param name="xpath">The XPath expression.</param> /// <returns>An <see cref="HtmlNodeCollection"/> containing a collection of nodes matching the <see cref="XPath"/> query, or <c>null</c> if no node matched the XPath expression.</returns> public HtmlNodeCollection SelectNodes(string xpath) { HtmlNodeCollection list = new HtmlNodeCollection(null); HtmlNodeNavigator nav = new HtmlNodeNavigator(OwnerDocument, this); XPathNodeIterator it = nav.Select(xpath); while (it.MoveNext()) { HtmlNodeNavigator n = (HtmlNodeNavigator)it.Current; list.Add(n.CurrentNode); } return list; }
public void GetLinksReturnsCorrectValue() { // check that there is no exception and it returns empty list Assert.Equal(0, GetLinks(null).Count); // check with the predefined html HtmlDocument doc = new HtmlDocument(); Page page = PageDocumentTestHelper.GetTestPage(3); doc.LoadHtml(page.Content); HtmlNodeCollection col = new HtmlNodeCollection(doc.DocumentNode); foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]")) col.Add(link); Assert.Equal(129, GetLinks(col).Count); }
/// <summary> /// Selects a list of nodes matching the <see cref="XPath"/> expression. /// </summary> /// <param name="xpath">The XPath expression.</param> /// <returns>An <see cref="HtmlNodeCollection"/> containing a collection of nodes matching the <see cref="XPath"/> query, or <c>null</c> if no node matched the XPath expression.</returns> public HtmlNodeCollection SelectNodes(string xpath) { HtmlNodeCollection list = new HtmlNodeCollection(null); HtmlNodeNavigator nav = new HtmlNodeNavigator(OwnerDocument, this); XPathNodeIterator it = nav.Select(xpath); while (it.MoveNext()) { HtmlNodeNavigator n = (HtmlNodeNavigator)it.Current; list.Add(n.CurrentNode); } return(list); }
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); }
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); }
/// <summary> /// Selects a list of nodes matching the <see cref="XPath"/> expression. /// </summary> /// <param name="xpath">The XPath expression.</param> /// <returns>An <see cref="HtmlNodeCollection"/> containing a collection of nodes matching the <see cref="XPath"/> query, or <c>null</c> if no node matched the XPath expression.</returns> public HtmlNodeCollection SelectNodes(XPathExpression xpath) { HtmlNodeCollection list = new HtmlNodeCollection(null); HtmlNodeNavigator nav = new HtmlNodeNavigator(OwnerDocument, this); XPathNodeIterator it = nav.Select(xpath); while (it.MoveNext()) { HtmlNodeNavigator n = (HtmlNodeNavigator)it.Current; list.Add(n.CurrentNode, false); } if (list.Count == 0 && !OwnerDocument.OptionEmptyCollection) { return(null); } return(list); }
private void GoToPageAndGetTableNodes(string startUrl, string pageUrl, HtmlNodeCollection allTableNodesForMonth) { string url = startUrl + pageUrl; bool haveNextPage = true; do { // Get all links for the first page HtmlWeb web = new HtmlWeb(); HtmlDocument doc = web.Load(url); HtmlNodeCollection tableNodes = doc.DocumentNode.SelectNodes("//tr[@class='roweven']|//tr[@class='rowodd']"); foreach (var node in tableNodes) { allTableNodesForMonth.Add(node); } // Get links for the other pages HtmlNode nextPage = null; if (doc.DocumentNode.SelectNodes("//td[@class='pagenumber']") != null) { nextPage = doc.DocumentNode.SelectNodes("//td[@class='pagenumber']").LastOrDefault(); } if (nextPage != null) { var linkNode = nextPage.FirstChild; if (linkNode.Attributes["href"] != null) { url = startUrl + "/cgi-bin/rechtsprechung/" + linkNode.Attributes["href"].Value; url = url.Replace("amp;", string.Empty); } else { haveNextPage = false; } } else { haveNextPage = false; } } while (haveNextPage); }
/// <summary> /// Selects a list of nodes matching the XPath expression. /// </summary> /// <param name="xpath">The XPath expression.</param> /// <returns>An HtmlNodeCollection containing a collection of nodes matching the XPath query, or null if no node matched the XPath expression.</returns> public HtmlNodeCollection SelectNodes(string xpath) { HtmlNodeCollection list = new HtmlNodeCollection(null); try { HtmlNodeNavigator nav = new HtmlNodeNavigator(_ownerdocument, this); XPathNodeIterator it = nav.Select(xpath); while (it.MoveNext()) { HtmlNodeNavigator n = (HtmlNodeNavigator)it.Current; list.Add(n.CurrentNode); } } catch (Exception ex) { O2.Kernel.ExtensionMethods.Logging_ExtensionMethods.log(ex, "in HtmlNodeCollection SelectNodes"); } //DC removed this so that we get an empty list when there are no matching nodes //if (list.Count == 0) //{ // return null; //} return list; }
public override HtmlNodeCollection get_gallery_items_nodes(HtmlNode root) { var node_items = new HtmlNodeCollection (null); var items = base.get_gallery_items_nodes (root); foreach (var item in items) { // skip signatures if (item.Attributes.Contains ("class") && item.Attributes ["class"].Value.Contains ("signature")) { continue; } var nodes = item.SelectNodes (".//a"); if (nodes != null) { foreach (var node in nodes) { node_items.Add (node); } } } return node_items; }
private void FinalizeHtmlDocument(IList<ArelleColumnSection> outlist) { var mtn = this.mainTableNode; for (int i = 0; i < mtn.ChildNodes.Count; i++) { mtn.ChildNodes[i].RemoveAllChildren(); var row = new HtmlNodeCollection(mtn.ChildNodes[i]); foreach (var item in outlist[i].DynamicColumns) { row.Add(item); } foreach (var item in outlist[i].NewStaticColumns) { row.Add(item); } mtn.ChildNodes[i].AppendChildren(row); } }
/// <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; }