SHARE
TWEET

How to parse an RSS feed using JavaScript in QuarkXPress (JQ

sarbjit2k Jul 23rd, 2018 (edited) 40 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Import jQuery Library from the CDN, you don't even need to download it!
  2. app.importScript("https://code.jquery.com/jquery-3.3.1.js");
  3.  
  4. (function () {
  5.  
  6.     //Specify the RSS Feed Link
  7.     const rssFeed = "http://forums.quark.com/feed.php";
  8.     //Check the feed to know which Tag is used for each entry, specify the correct Tag here
  9.     const rssPostTag = "entry";
  10.     //Create an array of Article Tags you want to fetch from the feed
  11.     const keysToRead = ["title", "author", "id"];
  12.  
  13.     //Call the function to read the feed
  14.     readRSS();
  15.  
  16.     //*****************====================================Functions used in the JavaScript===============================****************//
  17.  
  18.     function readRSS() {
  19.         let articleList = []; //Create an array to store articles
  20.         let article; //variable to store each article
  21.         let promise = new Promise(function (resolve, reject)//promise is used to ensure this task completes and returns a promise followed by further execution
  22.         {
  23.             //Load the RSS Feed XML using JQuery's "get" method
  24.             $.get(rssFeed, function (data) {
  25.                 //Parse all the "entries" in XML
  26.                 $(data).find(rssPostTag).each(function () {
  27.                     var el = $(this);
  28.                     //Create an object to store articles
  29.                     article = new Object();
  30.                     //Loop through all the required Tags and store them in the object
  31.                     for (let i = 0; i < keysToRead.length; i++) {
  32.                         article[keysToRead[i]] = el.find(keysToRead[i]).text();
  33.                     }
  34.  
  35.                     //Push to the list
  36.                     articleList.push(article);
  37.                     //Print the Element on the JavaScript Debugger console
  38.                     console.log(article);
  39.                 });
  40.  
  41.                 console.log("Found " + articleList.length + " articles in the feed.");
  42.             });
  43.  
  44.             // resolve(articleList);
  45.             Promise.resolve().then(resolve(articleList));
  46.         });
  47.         return promise;
  48.     }
  49.  
  50. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top