This is not a ‘pure’ R solution, but the Python sdmx1
package is fully usable through reticulate, and allows to programmatically generate SDMX objects and then serialize them as SDMX-ML (XML). For example:
# Use reticulate to import the Python package
> library(reticulate)
> sdmx <- import("sdmx")
# Create an (empty) DataMessage object
> msg <- sdmx$message$DataMessage()
# Convert to XML
> xml <- sdmx$to_xml(msg, pretty_print = TRUE)
# Write to file using the built-in R method
# The Python 'bytes' object must be decoded to a string
> write(xml$decode(), file = "message.xml")
This gives output like:
<mes:GenericData xmlns:com="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common" xmlns:data="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/structurespecific" xmlns:str="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/structure" xmlns:mes="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message" xmlns:gen="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/generic" xmlns:footer="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message/footer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<mes:Header>
<mes:Test>false</mes:Test>
</mes:Header>
</mes:GenericData>
For more information on authoring more complex messages using sdmx1
, there is a page “HOWTO Generate SDMX-ML from Python objects” in the documentation.