xml2 icon indicating copy to clipboard operation
xml2 copied to clipboard

Provide xml_clone()

Open hadley opened this issue 4 years ago • 3 comments

For when you want to modify a copy of an xml (sub)tree.

hadley avatar Jun 02 '21 17:06 hadley

+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.

MichaelChirico avatar Apr 17 '22 03:04 MichaelChirico