[R] XML namespace control

Ben Tupper btupper at bigelow.org
Mon Oct 29 13:54:27 CET 2012


Hello,

I am working with a database system from which I can retrieve these kinds of user defined fields formed as XML ...

<udf:field unit="uM" type="Numeric" name="facs.Stain final concentration">5</udf:field>

You can see in the above example that "field" is defined in the namespace "udf", but that the "udf" namespace is not defined along with the attributes of the node.  That is, 'xmlns:udf = "http://blah.blah.com/blah"' doesn't appear.  

I would like to create a similar node from scratch, but I can't seem to define the node with a namespace without providing the namespace definition. 


library(XML)

node1 <- newXMLNode("storm", "ripsnorter",
   namespace = "weather",
   namespaceDefinitions = c(weather = "http://my.weather.com/events"),
   attrs = c(type = "hurricane",  name = "Sandy"))
node1

# this returns the new node with the namespace prefix (which I want)
# and the definition (which I don't want)

# <weather:storm xmlns:weather="http://my.weather.com/events" type="hurricane" name="Sandy">ripsnorter</weather:storm>


node2 <- newXMLNode("storm", "ripsnorter",
   namespace = "weather",
   attrs = c(type = "hurricane",  name = "Sandy"),
   suppressNamespaceWarning = TRUE)
node2

# produces the node without the namespace prefix and without the definition

# <storm type="hurricane" name="Sandy">ripsnorter</storm>

Is there some way to create a node with a namespace prefix but without embedding the namespace definition along with the attributes?

Thanks!
Ben

Ben Tupper
Bigelow Laboratory for Ocean Sciences
180 McKown Point Rd. P.O. Box 475
West Boothbay Harbor, Maine   04575-0475 
http://www.bigelow.org


> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: i386-apple-darwin9.8.0/i386 (32-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tripack_1.3-4      RColorBrewer_1.0-5 Biostrings_2.24.1  IRanges_1.14.2     BiocGenerics_0.2.0 RCurl_1.91-1      
[7] bitops_1.0-4.1     XML_3.9-4         

loaded via a namespace (and not attached):
[1] stats4_2.15.0 tools_2.15.0



More information about the R-help mailing list