@@ -16,11 +16,12 @@ public static class Extensions
1616 /// Creates a new navigator for the given document.
1717 /// </summary>
1818 /// <param name="document">The document to extend.</param>
19+ /// <param name="ignoreNamespaces"></param>
1920 /// <returns>The navigator for XPath expressions.</returns>
20- public static XPathNavigator CreateNavigator ( this IDocument document )
21+ public static XPathNavigator CreateNavigator ( this IDocument document , bool ignoreNamespaces = true )
2122 {
2223 var doc = document ?? throw new ArgumentNullException ( nameof ( document ) ) ;
23- return new HtmlDocumentNavigator ( doc , doc . DocumentElement ) ;
24+ return new HtmlDocumentNavigator ( doc , doc . DocumentElement , ignoreNamespaces ) ;
2425 }
2526
2627 [ DebuggerStepThrough ]
@@ -35,14 +36,29 @@ internal static string GetOrAdd(this XmlNameTable table, string array)
3536 /// </summary>
3637 /// <param name="element">The element to start looking from.</param>
3738 /// <param name="xpath">The XPath expression.</param>
39+ /// <param name="ignoreNamespaces"></param>
3840 /// <returns>The node matching <paramref name="xpath"/> query, if any.</returns>
3941 /// <exception cref="ArgumentNullException">Throws if <paramref name="element"/> or <paramref name="xpath"/> is <c>null</c></exception>
40- public static INode SelectSingleNode ( this IElement element , string xpath )
42+ public static INode SelectSingleNode ( this IElement element , string xpath , bool ignoreNamespaces = true )
43+ {
44+ return element . SelectSingleNode ( xpath , new XmlNamespaceManager ( new NameTable ( ) ) , ignoreNamespaces ) ;
45+ }
46+
47+ /// <summary>
48+ /// Selects a single node (or returns null) matching the <see cref="XPath"/> expression.
49+ /// </summary>
50+ /// <param name="element">The element to start looking from.</param>
51+ /// <param name="xpath">The XPath expression.</param>
52+ /// <param name="resolver"></param>
53+ /// <param name="ignoreNamespaces"></param>
54+ /// <returns>The node matching <paramref name="xpath"/> query, if any.</returns>
55+ /// <exception cref="ArgumentNullException">Throws if <paramref name="element"/> or <paramref name="xpath"/> is <c>null</c></exception>
56+ public static INode SelectSingleNode ( this IElement element , string xpath , IXmlNamespaceResolver resolver , bool ignoreNamespaces = true )
4157 {
4258 var el = element ?? throw new ArgumentNullException ( nameof ( element ) ) ;
4359 var xp = xpath ?? throw new ArgumentNullException ( nameof ( xpath ) ) ;
44- var nav = new HtmlDocumentNavigator ( el . Owner , el ) ;
45- var it = nav . SelectSingleNode ( xp ) ;
60+ var nav = new HtmlDocumentNavigator ( el . Owner , el , ignoreNamespaces ) ;
61+ var it = nav . SelectSingleNode ( xp , resolver ?? new XmlNamespaceManager ( new NameTable ( ) ) ) ;
4662 return ( ( HtmlDocumentNavigator ) it ) ? . CurrentNode ;
4763 }
4864
@@ -51,14 +67,29 @@ public static INode SelectSingleNode(this IElement element, string xpath)
5167 /// </summary>
5268 /// <param name="element">The element to start looking from.</param>
5369 /// <param name="xpath">The XPath expression.</param>
70+ /// <param name="ignoreNamespaces"></param>
71+ /// <returns>List of nodes matching <paramref name="xpath"/> query.</returns>
72+ /// <exception cref="ArgumentNullException">Throws if <paramref name="element"/> or <paramref name="xpath"/> is <c>null</c></exception>
73+ public static List < INode > SelectNodes ( this IElement element , string xpath , bool ignoreNamespaces = true )
74+ {
75+ return element . SelectNodes ( xpath , new XmlNamespaceManager ( new NameTable ( ) ) , ignoreNamespaces ) ;
76+ }
77+
78+ /// <summary>
79+ /// Selects a list of nodes matching the <see cref="XPath"/> expression.
80+ /// </summary>
81+ /// <param name="element">The element to start looking from.</param>
82+ /// <param name="xpath">The XPath expression.</param>
83+ /// <param name="resolver"></param>
84+ /// <param name="ignoreNamespaces"></param>
5485 /// <returns>List of nodes matching <paramref name="xpath"/> query.</returns>
5586 /// <exception cref="ArgumentNullException">Throws if <paramref name="element"/> or <paramref name="xpath"/> is <c>null</c></exception>
56- public static List < INode > SelectNodes ( this IElement element , string xpath )
87+ public static List < INode > SelectNodes ( this IElement element , string xpath , IXmlNamespaceResolver resolver , bool ignoreNamespaces = true )
5788 {
5889 var el = element ?? throw new ArgumentNullException ( nameof ( element ) ) ;
5990 var xp = xpath ?? throw new ArgumentNullException ( nameof ( xpath ) ) ;
60- var nav = new HtmlDocumentNavigator ( el . Owner , el ) ;
61- var it = nav . Select ( xp ) ;
91+ var nav = new HtmlDocumentNavigator ( el . Owner , el , ignoreNamespaces ) ;
92+ var it = nav . Select ( xp , resolver ?? new XmlNamespaceManager ( new NameTable ( ) ) ) ;
6293 var result = new List < INode > ( ) ;
6394
6495 while ( it . MoveNext ( ) )
0 commit comments