extract_dsd: Extract the Data Structure Definition content from SDMX XML

View source: R/extract_dsd.R

extract_dsdR Documentation

Extract the Data Structure Definition content from SDMX XML

Description

Extracts values from the XML Data Structure Definition (DSD) file

Usage

extract_dsd(concept = NULL, dsd_xml = NULL, lang = "en")

Arguments

concept

a character vector with a concept id

dsd_xml

an XML file with DSD content

lang

a character string either en, de or fr to define the language version for the name column of the DSD. It is used only in the new API. The default is en - English.

Details

It is a sub-function to use in the get_eurostat_dsd function.

Value

a matrix with 3 columns if the provided concept has a code list in the DSD file. The first column is the provided concept. The second column is the possible codes under the given concept. The last column is the name/description for the code in the second column, which can be used as labels.

Examples



id<-"med_rd6"
cfg<-get("cfg",envir=restatapi::.restatapi_env)
rav<-get("rav",envir=restatapi::.restatapi_env)
dsd_url <- paste0(eval(
     parse(text=paste0("cfg$QUERY_BASE_URL$'",rav,"'$ESTAT$metadata$'2.1'$datastructure"))
   ),"/",eval(
     parse(text=paste0("cfg$QUERY_PRIOR_ID$'",rav,"'$ESTAT$metadata"))
   ),id,"?",eval(
     parse(text=paste0("cfg$QUERY_PARAMETERS$'",rav,"'$metadata[2]"))
   ),"=",eval(
     parse(text=paste0("cfg$DATAFLOW_REFERENCES$'",rav,"'$datastructure[1]"))
   )
 )
options(timeout=2)
tryCatch({
  dsd_xml<-xml2::read_xml(dsd_url)}, 
  error=function(e){
  message("Unable to download the xml file.\n",e)}, 
  warning=function(w){
  message("Unable to download the xml file.\n",w)}) 
if (exists("dsd_xml")) {extract_dsd("GEO",dsd_xml)} 
options(timeout=2)


restatapi documentation built on Sept. 19, 2023, 5:08 p.m.