diff --git a/src/Css/Css.csproj b/src/Css/Css.csproj index 1ef144f..0e4d013 100644 --- a/src/Css/Css.csproj +++ b/src/Css/Css.csproj @@ -14,6 +14,7 @@ + diff --git a/src/Css/CssSelectorExtensions.cs b/src/Css/CssSelectorExtensions.cs index 6c1d502..ff11243 100644 --- a/src/Css/CssSelectorExtensions.cs +++ b/src/Css/CssSelectorExtensions.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Xml.Linq; @@ -20,8 +21,11 @@ public static class CssSelectorExtensions /// The on which to evaluate the XPath expression. /// A that contains a CSS3 selector expression. /// An , or null. - public static XElement CssSelectElement(this XNode node, string expression) + public static XElement? CssSelectElement(this XNode? node, string expression) { + if (node == null) + return null; + var selector = Parser.Parse(expression); var xpath = selector.ToXPath(); return node.XPathSelectElement(xpath); @@ -35,8 +39,11 @@ public static XElement CssSelectElement(this XNode node, string expression) /// An of that /// contains the selected elements. /// - public static IEnumerable CssSelectElements(this XNode node, string expression) + public static IEnumerable CssSelectElements(this XNode? node, string expression) { + if (node == null) + return Array.Empty(); + var selector = Parser.Parse(expression); var xpath = selector.ToXPath(); return node.XPathSelectElements(xpath, new CssContext()); diff --git a/src/Css/Parser.cs b/src/Css/Parser.cs index 4a54765..f4c1b0f 100644 --- a/src/Css/Parser.cs +++ b/src/Css/Parser.cs @@ -1,7 +1,6 @@ using System; using System.Linq; using Superpower; -using Superpower.Model; using Superpower.Parsers; namespace Devlooped.Xml.Css;