Open sbrl opened 5 years ago
I am afraid, it's not supported at the moment.
I am guessing your use case is such that your root element is not <html>
and so you cannot select it with the type selector html
?
Ah, I suspected as much.
Something like that, yeah.
I'm actually writing an Atom feed generator (PolyFeed!), and in the configuration file I have an option to select the HTML elements that should form the basis of the items in the Atom feed.
For each element there are then a number of other different selectors to match against the elements that contain various pieces of information (e.g. the author's name, for example), which I have separate options to specify the attribute on the selected element to extract the information from. I want to be able to hit against the 'root' element here, as I'm making these secondary matches with a subNode.QuerySelector("selector here")
.
In theory, I could do this by testing if(selector == ":root") return htmlNode else return htmlNode.QuerySelector(selector);
, but it'd be great if I didn't have to wrap it :P
Thanks for the detailed explanation, @sbrl, and I think I see where you are going with this.
While adding support for :root
is not particularly difficult, it is designed to only work in a very specific scenario that I am not sure will help your case. You see, a *:root
query doesn't make sense or doesn't work unless it is started from the document node, which is hierarchically above the root element. In other words, you can't get to the root element from a query on the child element, which is what I think you are trying to get at. So piggy-backing on :root
in the way you want (that is, if (selector == ":root") return htmlNode else return htmlNode.QuerySelector(selector)
) would have to be an enhancement specific to your application anyhow.
Ah, I see. Looks like it doesn't work in the way I thought it would. I didn't realise that :root
is relative to the top-level document node and not the child element from which you're running the query.
I'll leave this issue open as a feature request anyway though.
Hey!
I've got a particular use-case whereby I sometimes need to select against the
:root
element, but Fizzler doesn't appear to support it: