Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide xml_clone() #341

Open
hadley opened this issue Jun 2, 2021 · 2 comments
Open

Provide xml_clone() #341

hadley opened this issue Jun 2, 2021 · 2 comments
Labels
feature a feature request or enhancement

Comments

@hadley
Copy link
Member

hadley commented Jun 2, 2021

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

@MichaelChirico
Copy link
Contributor

+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) ➡️ 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.

@t-kalinowski
Copy link
Member

+1, this would be quite useful for when you want to make destructive edits to the tree in a function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants