############################################################################ # read the data that you want to load in to ODK central ############################################################################ df<-read.csv("db.csv") names(df) ############################################################################ # Show the data ############################################################################ df #Name Age Happy #1 Wanda 34 Yes #2 Amaya 12 No #3 Darius 44 Yes #4 LaWayne 66 Yes ############################################################################ # show the names of fields in df ############################################################################ names(df) #"Name" "Age" "Happy" ############################################################################ # Create a set of dummy UUIDs in the format # uuid00d0d00b-b0d0-40e0-a000-0ce0a0bdafa0 # These are hex codes ############################################################################ hex.code<-function(){ paste0( paste0(sample(c(0:9, LETTERS[1:6]), 8, T),collapse = ""),"-", paste0(sample(c(0:9, LETTERS[1:6]), 4, T),collapse = ""),"-", paste0(sample(c(0:9, LETTERS[1:6]), 4, T),collapse = ""),"-", paste0(sample(c(0:9, LETTERS[1:6]), 4, T),collapse = ""),"-", paste0(sample(c(0:9, LETTERS[1:6]), 12, T),collapse = "") ) } # The uuid code is slightly different for the folder name inside instances folder, so make two versions df$hex.code<-NA for(i in 1:nrow(df)){df$hex.code[i]<-hex.code()} df$uuid<-paste0("uuid:",df$hex.code) df$uuid2<-paste0("uuid",df$hex.code) ############################################################################ # define a function that can parse the data from df in to the proforma xml file ############################################################################ xx<-function(row,df) { x<-paste0(c( '', df$Name[row], '', df$Age[row], '', df$Happy[row], '', df$uuid[row], '' )) x<-paste(x,collapse = "") dir.create(paste0("ODK Briefcase Storage/forms/prepopulate_example/instances/",df$uuid2[i]),showWarnings = F) write.table(file = paste0("ODK Briefcase Storage/forms/prepopulate_example/instances/",df$uuid2[i],"/submission.xml"),x = x ,quote = F,row.names = F,col.names = F) } ############################################################################ # Run the function on all lines of the csv file # Saving each row to a separate xml file in a named subfolder of instances ############################################################################ for(i in 1:nrow(df)){xx(row = i,df=df)}