File: SDMXType-methods.R

package info (click to toggle)
r-cran-rsdmx 1%3A0.6-5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,024 kB
  • sloc: sh: 14; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,180 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#' @name SDMXType
#' @rdname SDMXType
#' @aliases SDMXType,SDMXType-method
#' 
#' @usage
#' SDMXType(xmlObj)
#' 
#' @param xmlObj object of class "XMLInternalDocument derived from XML package
#' @return an object of class "SDMXType"
#' 
#' @note
#' At now, the following types have been implemented and successfully tested:
#'  - \code{StructureType},
#'  - \code{GenericDataType},
#'  - \code{CompactDataType},
#'  - \code{StructureSpecificDataType},
#'  - \code{CrossSectionalDataType},
#'  - \code{UtilityDataType},
#'  - \code{MessageGroupType}
#' 
#' @seealso \link{readSDMX}
#' 
#' @export
#'
SDMXType <- function(xmlObj){
	new("SDMXType", type = type.SDMXType(xmlObj));
}

type.SDMXType <- function(xmlObj){
  
  child <- xmlRoot(xmlObj)
  if(xmlName(child) == "RegistryInterface"){
    child <- xmlChildren(child)[[2]]
    if(xmlName(child) == "QueryStructureResponse") return("StructureType")
  }
  
  type <- xmlName(xmlRoot(xmlObj))
  if(attr(regexpr(":", type, ignore.case = T),"match.length") > 0){
    type <-strsplit(xmlName(xmlRoot(xmlObj), full=T), ":")[[1]][2]
  }  
	res <- paste(type, "Type", sep="");
	return(res)
}