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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
#' @name SDMXDimension
#' @rdname SDMXDimension
#' @aliases SDMXDimension,SDMXDimension-method
#'
#' @usage
#' SDMXDimension(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 "SDMXDimension"
#'
#' @seealso \link{readSDMX}
#' @export
#'
SDMXDimension <- function(xmlObj, namespaces){
sdmxVersion <- version.SDMXSchema(xmlDoc(xmlObj), namespaces)
VERSION.21 <- sdmxVersion == "2.1"
messageNs <- findNamespace(namespaces, "message")
strNs <- findNamespace(namespaces, "structure")
#manage SDMX 2.1 conceptIdentity and codelist LocalRepresentation
conceptRefXML <- NULL
if(VERSION.21){
conceptIdentityXML <- getNodeSet(xmlDoc(xmlObj),
"//str:ConceptIdentity",
namespaces = c(str = as.character(strNs)))
if(length(conceptIdentityXML) > 0)
conceptRefXML <- xmlChildren(conceptIdentityXML[[1]])[[1]]
}
codelistRefXML <- NULL
if(VERSION.21){
enumXML <- getNodeSet(xmlDoc(xmlObj),
"//str:Enumeration",
namespaces = c(str = as.character(strNs)))
if(length(enumXML) > 0)
codelistRefXML <- xmlChildren(enumXML[[1]])[[1]]
}
#attributes
#=========
conceptRef <- NULL
conceptVersion <- NULL
conceptAgency <- NULL
conceptSchemeRef <- NULL
conceptSchemeVersion <- NULL
conceptSchemeAgency <- NULL
codelist <- NULL
codelistVersion <- NULL
codelistAgency <- NULL
isMeasureDimension <- NULL
isFrequencyDimension <- NULL
isEntityDimension <- NULL
isCountDimension <- NULL
isNonObservationTimeDimension <- NULL
isIdentityDimension <- NULL
crossSectionalAttachDataset <- NULL
crossSectionalAttachGroup <- NULL
crossSectionalAttachSection <- NULL
crossSectionalAttachObservation <- NULL
if(VERSION.21){
#concepts
if(!is.null(conceptRefXML)){
conceptRef = xmlGetAttr(conceptRefXML, "id")
package = xmlGetAttr(conceptRefXML, "package")
if(package == "conceptscheme"){
conceptSchemeRef = xmlGetAttr(conceptRefXML, "maintainableParentID")
conceptSchemeVersion = xmlGetAttr(conceptRefXML, "maintainableParentVersion")
conceptSchemeAgency = xmlGetAttr(conceptRefXML, "agencyID")
}else{
conceptVersion = xmlGetAttr(conceptRefXML, "maintainableParentVersion")
conceptAgency = xmlGetAttr(conceptRefXML, "agencyID")
}
}
#codelists
if(!is.null(codelistRefXML)){
codelist <- xmlGetAttr(codelistRefXML, "id")
codelistVersion <- xmlGetAttr(codelistRefXML, "version")
codelistAgency <- xmlGetAttr(codelistRefXML, "agencyID")
}
#dimension characteristics
#TODO isMeasureDimension?
#TODO isFrequencyDimension?
#TODO isEntityDimension?
#TODO isLogicalDimension?
#TODO isNonObservationTimeDimension?
#TODO isIdentityDimension?
#crossSectionalAttach
#TODO crossSectionalAttachDataset?
#TODO crossSectionalAttachGroup?
#TODO crossSectionalAttachSection?
#TODO crossSectionalAttachObservation?
}else{
#concepts
conceptRef = xmlGetAttr(xmlObj, "conceptRef")
conceptVersion = xmlGetAttr(xmlObj, "conceptVersion")
conceptAgency = xmlGetAttr(xmlObj, "conceptAgency")
conceptSchemeRef = xmlGetAttr(xmlObj, "conceptSchemeRef")
conceptSchemeAgency = xmlGetAttr(xmlObj, "conceptSchemeAgency")
#codelists
codelist = xmlGetAttr(xmlObj, "codelist")
codelistVersion = xmlGetAttr(xmlObj, "codelistVersion")
codelistAgency = xmlGetAttr(xmlObj, "codelistAgency")
#dimensions characteristics
isMeasureDimension = xmlGetAttr(xmlObj, "isMeasureDimension")
isFrequencyDimension = xmlGetAttr(xmlObj, "isFrequencyDimension")
isEntityDimension = xmlGetAttr(xmlObj, "isEntityDimension")
isCountDimension = xmlGetAttr(xmlObj, "isCountDimension")
isNonObservationTimeDimension = xmlGetAttr(xmlObj,"isNonObservationTimeDimension")
isIdentityDimension = xmlGetAttr(xmlObj, "isIdentityDimension")
#crossSectionalAttach
crossSectionalAttachDataset = xmlGetAttr(xmlObj, "crossSectionalAttachDataset")
crossSectionalAttachGroup = xmlGetAttr(xmlObj, "crossSectionalAttachGroup")
crossSectionalAttachSection = xmlGetAttr(xmlObj, "crossSectionalAttachSection")
crossSectionalAttachObservation = xmlGetAttr(xmlObj,"crossSectionalAttachObservation")
}
if(is.null(conceptRef)) conceptRef <- as.character(NA)
if(is.null(conceptVersion)) conceptVersion <- as.character(NA)
if(is.null(conceptAgency)) conceptAgency <- as.character(NA)
if(is.null(conceptSchemeRef)) conceptSchemeRef <- as.character(NA)
if(is.null(conceptSchemeVersion)) conceptSchemeVersion <- as.character(NA)
if(is.null(conceptSchemeAgency)) conceptSchemeAgency <- as.character(NA)
if(is.null(codelist)) codelist <- as.character(NA)
if(is.null(codelistVersion)) codelistVersion <- as.character(NA)
if(is.null(codelistAgency)) codelistAgency <- as.character(NA)
if(is.null(isMeasureDimension)){
isMeasureDimension <- FALSE
}else{
isMeasureDimension <- as.logical(isMeasureDimension)
}
if(is.null(isFrequencyDimension)){
isFrequencyDimension <- FALSE
}else{
isFrequencyDimension <- as.logical(isFrequencyDimension)
}
if(is.null(isEntityDimension)){
isEntityDimension <- FALSE
}else{
isEntityDimension <- as.logical(isEntityDimension)
}
if(is.null(isCountDimension)){
isCountDimension <- FALSE
}else{
isCountDimension <- as.logical(isCountDimension)
}
if(is.null(isNonObservationTimeDimension)){
isNonObservationTimeDimension <- FALSE
}else{
isNonObservationTimeDimension <- as.logical(isNonObservationTimeDimension)
}
if(is.null(isIdentityDimension)){
isIdentityDimension <- FALSE
}else{
isIdentityDimension <- as.logical(isIdentityDimension)
}
if(is.null(crossSectionalAttachDataset)){
crossSectionalAttachDataset <- NA
}else{
crossSectionalAttachDataset <- as.logical(crossSectionalAttachDataset)
}
if(is.null(crossSectionalAttachGroup)){
crossSectionalAttachGroup <- NA
}else{
crossSectionalAttachGroup <- as.logical(crossSectionalAttachGroup)
}
if(is.null(crossSectionalAttachSection)){
crossSectionalAttachSection <- NA
}else{
crossSectionalAttachSection <- as.logical(crossSectionalAttachSection)
}
if(is.null(crossSectionalAttachObservation)){
crossSectionalAttachObservation <- NA
}else{
crossSectionalAttachObservation <- as.logical(crossSectionalAttachObservation)
}
#elements
#========
#TextFormat TODO
#instantiate the object
obj<- new("SDMXDimension",
#attributes
conceptRef = conceptRef,
conceptVersion = conceptVersion,
conceptAgency = conceptAgency,
conceptSchemeRef = conceptSchemeRef,
conceptSchemeVersion = conceptSchemeVersion,
conceptSchemeAgency = conceptSchemeAgency,
codelist = codelist,
codelistVersion = codelistVersion,
codelistAgency = codelistAgency,
isMeasureDimension = isMeasureDimension,
isFrequencyDimension = isFrequencyDimension,
isEntityDimension = isEntityDimension,
isCountDimension = isCountDimension,
isNonObservationTimeDimension = isNonObservationTimeDimension,
isIdentityDimension = isIdentityDimension,
crossSectionalAttachDataset = crossSectionalAttachDataset,
crossSectionalAttachGroup = crossSectionalAttachGroup,
crossSectionalAttachSection = crossSectionalAttachSection,
crossSectionalAttachObservation = crossSectionalAttachObservation
#elements,
#TextFormat = TextFormat
)
}
|