Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to parse the title of each item of a feed in Google Apps Scripts

I try to simply parse a RSS feed, but i get an error. How can i get the "Title" of each item?
It says "Cannot read property ‘getText’ of null"

I have no clue how i can debug this.

function parseFeed() {
  var feed = UrlFetchApp.fetch("https://www.reddit.com/r/GoogleAppsScript.rss?limit=1000").getContentText();
  feed = XmlService.parse(feed);

  var namespace = XmlService.getNamespace("http://www.w3.org/2005/Atom");
  var items = feed.getRootElement().getChildren("entry", namespace);  

items.forEach(item => {
    var title = item.getChild('title').getText();
    Logger.log(title);
});

}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

When your showing script is modified, how about the following modification?

From:

var title = item.getChild('title').getText();

To:

var title = item.getChild('title', namespace).getText();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading