Skip to content

Instantly share code, notes, and snippets.

@multidis
Created December 9, 2013 01:51
Show Gist options
  • Save multidis/7866331 to your computer and use it in GitHub Desktop.
Save multidis/7866331 to your computer and use it in GitHub Desktop.
Reading xml file of Excel shcema `xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml"` using xml-package (Omegahat) functions. NOTE: this is not newer Excel doc format, but older xml. Used as [Surveygizmo](http://www.surveygizmo.com/) export for example.
library(XML)
#file.xml <- # assign it
## list of row-nodes
lsrows <- xmlChildren(xmlRoot(xmlTreeParse(file.xml))[["Worksheet"]][["Table"]])
## row names are lsrows[[1]]
nms.rows <- xmlSApply(lsrows[[1]], xmlValue)
## spreadsheet values for each row are lsrows[[2,...]]
lsvals <- lapply(lsrows[-1], function(r) xmlSApply(r, xmlValue))
## now use list to form a data frame or process otherwise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment