Created
March 5, 2023 08:48
-
-
Save sengiv/d9304f9786c1f1bdb134af29bb633dc4 to your computer and use it in GitHub Desktop.
Simple JS function to find and retrieve text from xml file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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