Simple script for beginning developer

Hi everyone! I’m a long-time Airtable user and novice developer. I’m currently teaching myself Javascript and have a small script I’m trying to create (at least I think it’s small/simple).

I want to create a script that loops through a list of sitemap urls and returns the total count of pages for each record to a field in my table called “Page Count”

So far, I’ve been able to figure out that I can use a bit of javascript to count the number of xml nodes in a document using something like this:

var x = xmlDoc.getElementsByTagName("loc");
return(x.length);

But I’m not sure how to pull in an xml doc hosted at a specific url or loop through airtable records…anyone willing to provide a little direction?

Thanks,
Max

you would want to use the fetch() function. something like:

let urlContent = await fetch(sitemapLink)
let text = await urlContent.body()

let to convert that to an xml doc:

let parser = new DOMParser();
xmlDoc = parser.parseFromString(text,"text/xml");

good luck!

3 Likes

Ahhh thank you so much! This is very helpful for getting started, especially the fetch function and DOMParser

Did you get any errors at first with DOMParser?

I’m getting:
ReferenceError: DOMParser is not defined

From my understanding this isn’t supported?