Skip to main content

Simple script for beginning developer

  • March 18, 2020
  • 3 replies
  • 28 views

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

3 replies

Forum|alt.badge.img+19
  • Inspiring
  • 351 replies
  • March 18, 2020

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!


  • Author
  • Participating Frequently
  • 5 replies
  • March 18, 2020

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!


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


Forum|alt.badge.img+5
  • Known Participant
  • 11 replies
  • May 11, 2020

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?