There is no easy way to navigate up the parse tree provided by jsoup selector syntax. We currently can navigate down very easily with Jsoup's selector syntax value.parseHtml().select("div > p") and also value.parseHtml().select("div:has(@) ~ div") but
this does not directly allow DOM traversal itself. However, Jsoup conveniently provides DOM traversal for finding a https://jsoup.org/apidocs/org/jsoup/nodes/Element.html#parent()
which mimics the behavior from BeautifulSoup's https://www.crummy.com/software/BeautifulSoup/bs4/doc/#parent
Proposed solution
Add a new GREL function for the jsoup method parent() and for simplicity sake just call the GREL function parent()
Alternatives considered
A difficult path of custom installed Jython 2.7 with BeautifulSoup
Additional context
Existing code for select() functionality is here:
https://github.com/OpenRefine/OpenRefine/blob/master/main/src/com/google/refine/expr/functions/xml/SelectXml.java
and function registration to be added to is here:
https://github.com/OpenRefine/OpenRefine/blob/master/main/src/com/google/refine/grel/ControlFunctionRegistry.java#L249
There is no easy way to navigate up the parse tree provided by jsoup selector syntax. We currently can navigate down very easily with Jsoup's selector syntax
value.parseHtml().select("div > p")and alsovalue.parseHtml().select("div:has(@) ~ div")butthis does not directly allow DOM traversal itself. However, Jsoup conveniently provides DOM traversal for finding a https://jsoup.org/apidocs/org/jsoup/nodes/Element.html#parent()
which mimics the behavior from BeautifulSoup's https://www.crummy.com/software/BeautifulSoup/bs4/doc/#parent
Proposed solution
Add a new GREL function for the jsoup method
parent()and for simplicity sake just call the GREL functionparent()Alternatives considered
A difficult path of custom installed Jython 2.7 with BeautifulSoup
Additional context
Existing code for
select()functionality is here:https://github.com/OpenRefine/OpenRefine/blob/master/main/src/com/google/refine/expr/functions/xml/SelectXml.java
and function registration to be added to is here:
https://github.com/OpenRefine/OpenRefine/blob/master/main/src/com/google/refine/grel/ControlFunctionRegistry.java#L249