2014-03-19 56 views
0

我在流星中有一個cron作業設置(https://github.com/tmeasday/meteor-cron)。流星JS:解析XML的Cron作業

這裏是我的代碼:

var onetKeys = ["17-0000.00", 
      "27-0000.00", 
      "37-0000.00", 
      "13-0000.00", 
      "21-0000.00", 
      "15-0000.00", 
      "47-0000.00", 
      "25-0000.00", 
      "45-0000.00", 
      "35-0000.00", 
      "29-0000.00", 
      "49-0000.00", 
      "23-0000.00", 
      "19-0000.00", 
      "11-0000.00", 
      "43-0000.00", 
      "39-0000.00", 
      "51-0000.00", 
      "33-0000.00", 
      "41-0000.00", 
      "53-0000.00"]; 

console.log("[+] ==== Cron Jobs ===="); 

Meteor.startup(function(){ 

    cron = new Cron(); 

    cron.addJob(500, function(){ 

    var params = [], finalUrl; 

    $.each(onetKeys, function(i, onet){ 
     params.push("onet=" + onet); 
     params.push("cn=100"); 
     params.push("rs=1&re=500"); 
     finalUrl = params.join("&"); 

     Meteor.call('retrieveJobs', finalUrl, function(error, results){ 
     console.log('GOT JOBS'); 
     $('job', results.content).each(function(){ 
      var jvid = $(this).find('jvid').text(); 
      if(!Jobs.findOne({jvid: jvid})) { 
      options = {} 
      options.title = $(this).find('title').text(); 
      options.company = $(this).find('company').text(); 
      options.address = $(this).find('location').text(); 
      options.url = $(this).find('url').text(); 
      options.jvid = jvid; 
      options.dateacquired = $(this).find('dateacquired').text(); 
      var id = createJob(options); 
      console.log("Job Created: " + id); 
      } 
     }); 
     }); 
    }); 
    }) 
}) 

上面的代碼是project_root/cron.js,將與客戶端執行。我需要將其移出服務器,但不知道如何在沒有jQuery幫助的情況下處理XML(難道我知道)。如何在不使用jQuery的情況下解析JavaScript中的XML示例?

回答