Skip to content

Instantly share code, notes, and snippets.

@mickle00
Created July 30, 2014 22:33
Show Gist options
  • Save mickle00/581eb4d83ccacf72e95d to your computer and use it in GitHub Desktop.
Save mickle00/581eb4d83ccacf72e95d to your computer and use it in GitHub Desktop.
May need to truncate length of strings, XML encode ampersands, and fit into the rest of the XML
var jq = document.createElement('script');
jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
var outputString = '';
function getAPISafeLabel(name){
name = name.replace(/\ /g,'_');
name = name.replace(/\//g,'_');
name = name.replace(/\,/g,'_');
name = name.replace(/\&/g,'_');
name = name.replace(/\-/g,'_');
name = name.replace(/\_\_/g,'_');
name = name.replace(/\_\_/g,'_');
return name;
}
function getCategory(){
categories = document.getElementById('00NC0000004yBn3').options;
j$(categories).each(function(){
if (j$(this).val() !== ''){
var cat = j$(this).val();
outputString += '\n\t<dataCategory>\n\t\t<label>' + cat + '</label>\n\t\t<name>'+getAPISafeLabel(cat)+'</name>\n\t</dataCategory>';
}
});
}
function main(){
j$ = jQuery.noConflict();
types = document.getElementById('cas5').options;
j$(types).each(function(){
myType = j$(this).val()
outputString += '<dataCategory>';
j$('#cas5').val(myType);
j$(types).trigger('change');
getCategory();
outputString += '\n\t<label>' + myType + '</label>\n\t<name>' + getAPISafeLabel(myType) + '</name>\n</dataCategory>\n';
});
console.log(outputString);
}
setTimeout(main, 3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment