/// <summary> /// Moves to the same position as the specified HtmlNavigator. /// </summary> /// <param name="other">The HtmlNavigator positioned on the node that you want to move to.</param> /// <returns>true if successful, otherwise false. If false, the position of the navigator is unchanged.</returns> public override bool MoveTo(XPathNavigator other) { HtmlNodeNavigator nav = other as HtmlNodeNavigator; if (nav == null) { #if TRACE_NAVIGATOR InternalTrace(">false (nav is not an HtmlNodeNavigator)"); #endif return(false); } #if TRACE_NAVIGATOR InternalTrace("moveto oid=" + nav.GetHashCode() + ", n:" + nav._currentnode.Name + ", a:" + nav._attindex); #endif if (nav._doc == _doc) { _currentnode = nav._currentnode; _attindex = nav._attindex; #if TRACE_NAVIGATOR InternalTrace(">true"); #endif return(true); } // we don't know how to handle that #if TRACE_NAVIGATOR InternalTrace(">false (???)"); #endif return(false); }
private HtmlNodeNavigator(HtmlNodeNavigator nav) { if (nav == null) { throw new ArgumentNullException("nav"); } #if TRACE_NAVIGATOR InternalTrace(null); #endif _doc = nav._doc; _currentnode = nav._currentnode; _attindex = nav._attindex; _nametable = nav._nametable; // REVIEW: should we do this? }
/// <summary> /// Determines whether the current HtmlNavigator is at the same position as the specified HtmlNavigator. /// </summary> /// <param name="other">The HtmlNavigator that you want to compare against.</param> /// <returns>true if the two navigators have the same position, otherwise, false.</returns> public override bool IsSamePosition(XPathNavigator other) { HtmlNodeNavigator nav = other as HtmlNodeNavigator; if (nav == null) { #if TRACE_NAVIGATOR InternalTrace(">false"); #endif return(false); } #if TRACE_NAVIGATOR InternalTrace(">" + (nav._currentnode == _currentnode)); #endif return(nav._currentnode == _currentnode); }
/// <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="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"); } HtmlNodeNavigator nav = new HtmlNodeNavigator(OwnerDocument, this); XPathNodeIterator it = nav.Select(xpath); if (!it.MoveNext()) { return(null); } HtmlNodeNavigator node = (HtmlNodeNavigator)it.Current; return(node.CurrentNode); }
/// <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); }