Skip to content

Commit e1dcec6

Browse files
authored
Merge pull request #215 from PacificCommunity/master
SDMXCode to read parent codes properly
2 parents b724c69 + 9c90ba9 commit e1dcec6

File tree

3 files changed

+3098
-6
lines changed

3 files changed

+3098
-6
lines changed

R/SDMXCode-methods.R

+10-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,16 @@ SDMXCode <- function(xmlObj, namespaces){
3939
urn = xmlGetAttr(xmlObj, "urn")
4040
if(is.null(urn)) urn <- as.character(NA)
4141

42-
parentCode = xmlGetAttr(xmlObj, "parentCode")
43-
if(is.null(parentCode)) parentCode <- as.character(NA)
42+
parentCode <- as.character(NA)
43+
parentId <- xmlGetAttr(xmlObj, "parentCode")
44+
if(!is.null(parentId)) parentCode <- parentId
45+
parentNode <- getNodeSet(xmlDoc(xmlObj), "//ns:Parent//Ref", namespaces = strNs)
46+
if(length(parentNode) == 1) parentCode <- xmlGetAttr(parentNode[[1]], "id")
47+
if(length(parentNode) > 1) {
48+
parentCode <- sapply(parentNode, function(x) { xmlGetAttr(x, "id") })
49+
# we collapse the vector of parent codes into a single string as required by the SDMXCode class
50+
parentCode <- paste(parentCode, collapse = ",")
51+
}
4452

4553
#elements
4654
#========

0 commit comments

Comments
 (0)