xml2
xml2 copied to clipboard
Provide xml_clone()
For when you want to modify a copy of an xml (sub)tree.
+1 to this. Use case: I'd like to replace the gsub() kludge used to ...out the text to the offending call in lintr::seq_linter() here:
https://github.com/r-lib/lintr/blob/fc6cb377839ffb6862601e72c0e1b86f7ef00015/R/seq_linter.R#L31
(i.e., it maps 1:length(x) :arrow_right: 1:length(...))
It would be natural to use xml2::xml_text<- to do so, but this has cascading effects, e.g. the xml_parsed_content would then be edited for all other linters examining the parse tree.
The current workaround seems to be constructing a new XML document manually from the sub-tree, which is currently quite manual.
Even an API like xml2::xml_new_document(XML_OBJECT) that takes a (sub)tree as input and handles the grudge work of creating the new document would be nice.