Skip to content

Instantly share code, notes, and snippets.

@sengiv
Created March 5, 2023 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sengiv/d9304f9786c1f1bdb134af29bb633dc4 to your computer and use it in GitHub Desktop.
Save sengiv/d9304f9786c1f1bdb134af29bb633dc4 to your computer and use it in GitHub Desktop.
Simple JS function to find and retrieve text from xml file
//gets events from EventDataList.xml
//for viewing in time legend
async function getEventDescription(eventName) {
//search for matching event name
var eventXmlList = window.$EventDataListXml.find('Event'); //get all event elements
var results = eventXmlList.filter(
function () {
var eventNameXml = $(this).children('Name').eq(0);
return eventNameXml.text() === eventName;
});
//get description text out of the event xml record
var eventDescription = results.eq(0).children('Description').eq(0).text();
//remove tabs and new line to make easy detection of empty string
let cleaned = eventDescription.replace(/ {4}|[\t\n\r]/gm, '');
return cleaned;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment