function encodeXML(theString) { return theString.replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"'); } function generateQueryString(organizationScope, anyValue, searchFields) { // make sure it is valid XML var searchTerm = encodeXML(anyValue); var queryString = ""; queryString += ""; queryString += "metadata"; queryString += "-//ecoinformatics.org//eml-dataset-2.0.0beta6//EN"; queryString += "-//ecoinformatics.org//eml-dataset-2.0.0beta4//EN"; queryString += "eml://ecoinformatics.org/eml-2.1.1"; queryString += "eml://ecoinformatics.org/eml-2.1.0"; queryString += "eml://ecoinformatics.org/eml-2.0.1"; queryString += "eml://ecoinformatics.org/eml-2.0.0"; queryString += "-//NCEAS//eml-dataset-2.0//EN"; queryString += "-//NCEAS//resource//EN"; queryString += "originator/individualName/surName"; queryString += "originator/individualName/givenName"; queryString += "originator/organizationName"; queryString += "creator/individualName/surName"; queryString += "creator/organizationName"; queryString += "dataset/title"; queryString += "dataset/title/value"; queryString += "keyword"; queryString += "keyword/value"; queryString += "creator/individualName/givenName"; queryString += "idinfo/citation/citeinfo/title"; queryString += "idinfo/citation/citeinfo/origin"; queryString += "idinfo/keywords/theme/themekey"; queryString += ""; //search particular fields, or all? if (searchFields.length > 0) { queryString += ""; for (var i = 0; i < searchFields.length; i++) { queryString += ""; queryString += "" + searchTerm + ""; queryString += "" + searchFields[i] +""; queryString += ""; } queryString += ""; } else { queryString += ""; queryString += "" + searchTerm + ""; queryString += ""; } //now limit by the organization queryString += ""; for (var i = 0; i < organizationScope.length; i++) { queryString += ""; queryString += "" + organizationScope[i] + ""; queryString += "placekey"; queryString += ""; queryString += ""; queryString += "" + organizationScope[i] + ""; queryString += "keyword"; queryString += ""; } queryString += ""; queryString += ""; queryString += ""; //alert(queryString); return queryString; } function setQueryFormField() { //alert('setQueryFormField'); var queryField = document.getElementById("query"); //alert('queryField=' + queryField); var anyfieldField = document.getElementById("anyfield"); //alert('anyfieldField=' + anyfieldField); var organizationScopeField = document.getElementById("organizationScope"); //alert('organizationScopeField=' + organizationScopeField.value); var searchAll = document.getElementById("searchAll"); //alert('searchAll=' + searchAll.checked); //make the array for organization var orgArray = new Array(); orgArray[0] = organizationScopeField.value; //if "All", include multiple entries if (organizationScopeField.value == '') { orgArray[0] = "SANParks, South Africa"; orgArray[1] = "SAEON, South Africa"; } //make the array for paths to search var searchFieldArray = new Array(); if (!searchAll.checked) { var counter = 0; //EML fields searchFieldArray[counter++] = "abstract/para"; searchFieldArray[counter++] = "abstract/para/value"; searchFieldArray[counter++] = "surName"; searchFieldArray[counter++] = "givenName"; searchFieldArray[counter++] = "organizationName"; searchFieldArray[counter++] = "title"; searchFieldArray[counter++] = "title/value"; searchFieldArray[counter++] = "keyword"; searchFieldArray[counter++] = "keyword/value"; searchFieldArray[counter++] = "para"; searchFieldArray[counter++] = "geographicDescription"; searchFieldArray[counter++] = "literalLayout"; searchFieldArray[counter++] = "@packageId"; //FGDC fields searchFieldArray[counter++] = "abstract"; searchFieldArray[counter++] = "idinfo/citation/citeinfo/title"; searchFieldArray[counter++] = "idinfo/citation/citeinfo/origin"; searchFieldArray[counter++] = "idinfo/keywords/theme/themekey"; searchFieldArray[counter++] = "placekey"; } //generate the query queryField.value = generateQueryString( orgArray, anyfieldField.value, searchFieldArray); //alert(queryField.value); } function setBrowseAll() { //set the field to wildcard var anyfieldField = document.getElementById("anyfield"); anyfieldField.value = ""; //set the query setQueryFormField(); }