xml2 icon indicating copy to clipboard operation
xml2 copied to clipboard

xml_set_attrs removes namespace

Open JHLasbatre opened this issue 2 years ago • 2 comments

Hi team

I'm using xml2::xml_set_attrs to modify an xml us the following

# read xml from some file
xmlparent <- read_xml(XML_Input_Template_Path)

# find a specific path and add attributes to elements
xmlparent %>% xml_find_all(., xpath = ".//d1:command[@fragment='paramModelDate']/r:paramInstance") %>%
    xml_set_attrs(., c("xsi:type" = "FdbModelDate", "date" = as.character(as.Date(FDBDate, format = "%Y%m%d")), "model" = FDBModel, "repository" = FDB_Path))

Initialy my xml was lilke this:

After using xml_set_attrs the attributes are correctly modified but the namespace had been removed. How can I force it here ?

Thanks

JHLasbatre avatar Aug 27 '21 15:08 JHLasbatre

adding xml files correct wrong

JHLasbatre avatar Aug 27 '21 15:08 JHLasbatre

Can you please provide a minimal reprex (reproducible example)? The goal of a reprex is to make it as easy as possible for me to recreate your problem so that I can fix it: please help me help you! If you've never heard of a reprex before, start by reading about the reprex package, including the advice further down the page. Please make sure your reprex is created with the reprex package as it gives nicely formatted output and avoids a number of common pitfalls.

hadley avatar Feb 28 '22 20:02 hadley

I've closed this issue due to lack of requested reprex. If you still care about this bug, please open a new issue with a reprex.

hadley avatar Oct 30 '23 18:10 hadley