11using AngleSharp . Dom ;
22using AngleSharp . Dom . Html ;
33using System ;
4+ using System . Collections . Generic ;
5+ using System . Collections . Specialized ;
46using System . Diagnostics ;
57using System . Xml ;
68using System . Xml . XPath ;
@@ -22,7 +24,7 @@ public static XPathNavigator CreateNavigator(this IHtmlDocument document)
2224 [ DebuggerStepThrough ]
2325 public static string GetOrAdd ( this XmlNameTable table , string array )
2426 {
25- string s = table . Get ( array ) ;
27+ var s = table . Get ( array ) ;
2628
2729 if ( s == null )
2830 {
@@ -55,5 +57,38 @@ public static INode SelectSingleNode(this IElement element, string xpath)
5557 var node = ( HtmlDocumentNavigator ) it . Current ;
5658 return node . CurrentNode ;
5759 }
60+
61+ /// <summary>
62+ /// Selects a list of nodes matching the <see cref="XPath"/> expression.
63+ /// </summary>
64+ /// <param name="element"></param>
65+ /// <param name="xpath">The XPath expression.</param>
66+ /// <returns>List of nodes matching <paramref name="xpath"/> query.</returns>
67+ /// <exception cref="ArgumentNullException">Throws if <paramref name="element"/> or <paramref name="xpath"/> is <c>null</c></exception>
68+ public static List < INode > SelectNodes ( this IElement element , string xpath )
69+ {
70+ if ( element == null )
71+ {
72+ throw new ArgumentNullException ( nameof ( element ) ) ;
73+ }
74+
75+ if ( xpath == null )
76+ {
77+ throw new ArgumentNullException ( nameof ( xpath ) ) ;
78+ }
79+
80+ var nav = new HtmlDocumentNavigator ( element . Owner , element ) ;
81+ var it = nav . Select ( xpath ) ;
82+ var result = new List < INode > ( ) ;
83+
84+ while ( it . MoveNext ( ) )
85+ {
86+ var naviagtor = ( HtmlDocumentNavigator ) it . Current ;
87+ var e = naviagtor . CurrentNode ;
88+ result . Add ( e ) ;
89+ }
90+
91+ return result ;
92+ }
5893 }
5994}
0 commit comments