Help

Re: Parsing XML from a fetch

2506 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Tyler_Campbell
6 - Interface Innovator
6 - Interface Innovator

I’m fetching XML data text() but am running into a dead end when trying to find a way to parse the data. I tried using domparser and a few different functions I found on StackOverflow but most seem to require a non-native library. Does anyone have any suggestions on either how to parse XML in vanilla javascript or how to convert XML into JSON?

For reference when using

let parser = new DOMParser();

I get “ReferenceError: DOMParser is not defined”

4 Replies 4
openside
10 - Mercury
10 - Mercury

maybe try a simple function like this:

https://gist.github.com/petersirka/9e79b1d43cf6e579fc62

JavaScript - Simple XML parser
/**
 * Simple XML parser
 * @param {String} xml
 * @return {Object}
 */
function parseXML(xml) {

    var beg = -1;
    var end = 0;
    var tmp = 0;
This file has been truncated. show original

Tyler_Campbell
6 - Interface Innovator
6 - Interface Innovator

That worked for me once I realized it was parsing it into an object where I could use keys to get what I need. Thanks!

I found that this function doesn’t always parse data from the XML correctly, especially if there are characters like ‘<’ in the data itself.

Do you have any other recommendations on how to parse XML using another method?

For anyone from Google, you can try using the free Data Fetcher extension to import a remote XML file to Airtable.