/// <summary> /// Selects a single node (or returns null) matching the <see cref="XPath"/> expression. /// </summary> /// <param name="element">The element to start looking from.</param> /// <param name="xpath">The XPath expression.</param> /// <param name="resolver"></param> /// <param name="ignoreNamespaces"></param> /// <returns>The node matching <paramref name="xpath"/> query, if any.</returns> /// <exception cref="ArgumentNullException">Throws if <paramref name="element"/> or <paramref name="xpath"/> is <c>null</c></exception> public static INode SelectSingleNode(this IElement element, string xpath, IXmlNamespaceResolver resolver, bool ignoreNamespaces = true) { var el = element ?? throw new ArgumentNullException(nameof(element)); var xp = xpath ?? throw new ArgumentNullException(nameof(xpath)); var nav = new HtmlDocumentNavigator(el.Owner, el, ignoreNamespaces); var it = nav.SelectSingleNode(xp, resolver ?? new XmlNamespaceManager(new NameTable())); return(((HtmlDocumentNavigator)it)?.CurrentNode); }
public override bool IsSamePosition(XPathNavigator other) { HtmlDocumentNavigator navigator = other as HtmlDocumentNavigator; if (navigator == null) { return(false); } return(navigator._currentNode == _currentNode); }
/// <summary> /// Selects a single node (or returns null) matching the <see cref="XPath"/> expression. /// </summary> /// <param name="element">The element to start looking from.</param> /// <param name="xpath">The XPath expression.</param> /// <returns>The node matching <paramref name="xpath"/> query, if any.</returns> /// <exception cref="ArgumentNullException">Throws if <paramref name="element"/> or <paramref name="xpath"/> is <c>null</c></exception> public static INode SelectSingleNode(this IElement element, String xpath) { var el = element ?? throw new ArgumentNullException(nameof(element)); var xp = xpath ?? throw new ArgumentNullException(nameof(xpath)); var nav = new HtmlDocumentNavigator(el.Owner, el); var it = nav.Select(xp); if (it.MoveNext()) { var node = (HtmlDocumentNavigator)it.Current; return(node.CurrentNode); } return(null); }
/// <summary> /// Selects a list of nodes matching the <see cref="XPath"/> expression. /// </summary> /// <param name="element">The element to start looking from.</param> /// <param name="xpath">The XPath expression.</param> /// <returns>List of nodes matching <paramref name="xpath"/> query.</returns> /// <exception cref="ArgumentNullException">Throws if <paramref name="element"/> or <paramref name="xpath"/> is <c>null</c></exception> public static List <INode> SelectNodes(this IElement element, String xpath) { var el = element ?? throw new ArgumentNullException(nameof(element)); var xp = xpath ?? throw new ArgumentNullException(nameof(xpath)); var nav = new HtmlDocumentNavigator(el.Owner, el); var it = nav.Select(xp); var result = new List <INode>(); while (it.MoveNext()) { var naviagtor = (HtmlDocumentNavigator)it.Current; var e = naviagtor.CurrentNode; result.Add(e); } return(result); }
public override bool MoveTo(XPathNavigator other) { HtmlDocumentNavigator navigator = other as HtmlDocumentNavigator; if (navigator == null) { return(false); } if (navigator._document == _document) { _currentNode = navigator._currentNode; _attrIndex = navigator._attrIndex; return(true); } return(false); }
/// <summary> /// Selects a list of nodes matching the <see cref="XPath"/> expression. /// </summary> /// <param name="element">The element to start looking from.</param> /// <param name="xpath">The XPath expression.</param> /// <param name="resolver"></param> /// <param name="ignoreNamespaces"></param> /// <returns>List of nodes matching <paramref name="xpath"/> query.</returns> /// <exception cref="ArgumentNullException">Throws if <paramref name="element"/> or <paramref name="xpath"/> is <c>null</c></exception> public static List <INode> SelectNodes(this IElement element, string xpath, IXmlNamespaceResolver resolver, bool ignoreNamespaces = true) { var el = element ?? throw new ArgumentNullException(nameof(element)); var xp = xpath ?? throw new ArgumentNullException(nameof(xpath)); var nav = new HtmlDocumentNavigator(el.Owner, el, ignoreNamespaces); var it = nav.Select(xp, resolver ?? new XmlNamespaceManager(new NameTable())); var result = new List <INode>(); while (it.MoveNext()) { // ReSharper disable once IdentifierTypo var naviagtor = (HtmlDocumentNavigator)it.Current; // ReSharper disable once PossibleNullReferenceException var e = naviagtor.CurrentNode; result.Add(e); } return(result); }
public static INode SelectSingleNode(this IElement element, string xpath) { if (element == null) { throw new ArgumentNullException(nameof(element)); } if (xpath == null) { throw new ArgumentNullException(nameof(xpath)); } HtmlDocumentNavigator nav = new HtmlDocumentNavigator(element.Owner, element); XPathNodeIterator it = nav.Select(xpath); if (!it.MoveNext()) { return(null); } HtmlDocumentNavigator node = (HtmlDocumentNavigator)it.Current; return(node.CurrentNode); }