xml2 icon indicating copy to clipboard operation
xml2 copied to clipboard

xml_new_root should accept an xml_namespace object

Open cboettig opened this issue 7 years ago • 0 comments

Hey @jimhester,

I could be missing something, but it seems a bit clumsy that to define namespaces when calling xml_new_root there's no simple way to pass an existing xml_namespace object. For instance, the vignette gives us the following example:

d <- xml_new_root("sld",
    xmlns = "http://www.o.net/sld",
    "xmlns:ogc" = "http://www.o.net/ogc",
    "xmlns:se" = "http://www.o.net/se",
    version = "1.1.0") 

There's no simple way to read the namespaces from an existing doc and pass them to xml_new_root() or xml_new_doc as far as I can tell.

We can get the namespaces back as an xml_namespace object:

ns <- xml_ns(d)
class(ns)

but as far as I can tell, things get pretty cludgy if we want to pass this to xml_new_root:

names(ns) <- paste("xmlns", names(ns), sep=":")
do.call(xml_new_root, c(.value = "root", as.list(ns)))

Is there a way to do this without the do.call and manual pasting xmlns and all? Maybe xml_new_root & friends could be tweaked to take an xml_namespace object as argument directly? Thanks!

cboettig avatar Mar 07 '17 23:03 cboettig