The Darwin Core standard is a well established standard for archiving biodiversity data, including data from specimens in collections to observations of animals or plants at particular locations. I needed a simple formatted table describing the terms used in the Darwin Core standard, but struggled to find one. So, I wrote the script below wich parses the XML document containing the terms into a Google Spreadsheet. This will give two columns with the terms and the parent group to which they belong, if relevant, as well as a column containing the data type.
To execute the script, simply click on Script Editor, copy-paste the script below and click on Run!
function xmltowide() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getActiveRange();
var col = range.getColumn();
var row = range.getRow();
var data= range.getValues();
var url = 'http://rs.tdwg.org/dwc/xsd/tdwg_dwcterms.xsd';
var response = UrlFetchApp.fetch(url);
var xml = response.getContentText();
var document = XmlService.parse(xml);
var root = document.getRootElement();
var xmlschema = XmlService.getNamespace('http://www.w3.org/2001/XMLSchema');
/*var $title = $xml.find( "title" );*/
var entries = root.getChildren();
k=2;
for (var i = 0; i < entries.length; i++) {
var nameval=entries[i].getAttribute('name');
var subgroup=entries[i].getAttribute('substitutionGroup');
if(nameval){
sheet.getRange(k,2).setValue(nameval.getValue());
if(subgroup){
sheet.getRange(k,1).setValue(subgroup.getValue());
}
type=entries[i].getAttribute('type');
if(type){
sheet.getRange(k,3).setValue(type.getValue());
}
if(entries[i].getName()=='group') {
var sub1=entries[i].getChildren('sequence',xmlschema);
var subentries=sub1[0].getChildren();//SEQUENCES
var ll=subentries.length;
for (var j = 0; j < subentries.length; j++) {
sname=subentries[j].getAttribute('ref');
if (sname){
sheet.getRange(k,1).setValue(nameval.getValue());
sheet.getRange(k,2).setValue(sname.getValue());
k++
}
}
}else{
k++
}
}
}
}