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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#' @name SDMXOrganisation
#' @rdname SDMXOrganisation
#' @aliases SDMXOrganisation,SDMXOrganisation-method
#'
#' @usage
#' SDMXOrganisation(xmlObj, namespaces)
#'
#' @param xmlObj object of class "XMLInternalDocument derived from XML package
#' @param namespaces object of class "data.frame" given the list of namespace URIs
#' @return an object of class "SDMXOrganisation"
#'
#' @seealso \link{readSDMX}
#' @export
#'
SDMXOrganisation <- function(xmlObj, namespaces){
obj <- organisation.SDMXOrganisation(xmlObj, namespaces, "SDMXOrganisation")
}
organisation.SDMXOrganisation <- function(xmlObj, namespaces, klass){
messageNs <- findNamespace(namespaces, "message")
strNs <- findNamespace(namespaces, "structure")
sdmxVersion <- version.SDMXSchema(xmlDoc(xmlObj), namespaces)
VERSION.21 <- sdmxVersion == "2.1"
refNs <- strNs
if(VERSION.21){
comNs <- findNamespace(namespaces, "common")
refNs <- comNs
}
#attributes
#=========
id = xmlGetAttr(xmlObj, "id")
if(is.null(id)) id <- as.character(NA)
uri = xmlGetAttr(xmlObj, "uri")
if(is.null(uri)) uri <- as.character(NA)
urn = xmlGetAttr(xmlObj, "urn")
if(is.null(urn)) urn <- as.character(NA)
#elements
#========
#name (multi-languages)
orgNamesXML <- getNodeSet(xmlDoc(xmlObj), "//ns:Name", namespaces = refNs)
orgNames <- NULL
if(length(orgNamesXML) > 0){
orgNames <- new.env()
sapply(orgNamesXML,
function(x){
lang <- xmlGetAttr(x,"xml:lang")
if(is.null(lang)) lang <- xmlGetAttr(x,"lang")
if(is.null(lang)) lang <- "default"
orgNames[[lang]] <- xmlValue(x)
})
orgNames <- as.list(orgNames)
}
#description (multi-languages)
orgDesXML <- getNodeSet(xmlDoc(xmlObj), "//ns:Description", namespaces = refNs)
orgDescriptions <- list()
if(length(orgDesXML) > 0){
orgDescriptions <- new.env()
sapply(orgDesXML,
function(x){
lang <- xmlGetAttr(x,"xml:lang")
if(is.null(lang)) lang <- xmlGetAttr(x,"lang")
if(is.null(lang)) lang <- "default"
orgDescriptions[[lang]] <- xmlValue(x)
})
orgDescriptions <- as.list(orgDescriptions)
}
#instantiate the object
obj<- new(klass,
#attributes
id = id,
uri = uri,
urn = urn,
#elements
Name = orgNames,
Description = orgDescriptions
)
return(obj)
}
|