Using this function, it is possible to search an XML tree without the prerequisite of knowing XPath.
css_to_xpath(selector, prefix = "descendant-or-self::", translator = "generic")
""
are most commonly used.
generic
(the default), or html
or xhtml
.
""
, unless it is known what scope a particular XPath
expression should have. The translator used is usually unnecessary to specify as the default
is sufficient for most cases. However, it is of use when creating
expressions relating to (X)HTML pseudo elements and languages. In
particular it qualifies the following pseudo selectors to apply only
to relevant (X)HTML elements: :checked
, :disabled
,
:enabled
and :link
.
When the translator is set to html
, all elements and
attributes will be converted to lower case. This restriction is
removed when the translator is xhtml
(or the default
generic
translator).
css_to_xpath(".testclass")
css_to_xpath("#testid", prefix = "")
css_to_xpath("#testid .testclass")
css_to_xpath(":checked", translator = "html")
Run the code above in your browser using DataLab