using variable value in xpath and yql

You must Login before you can answer or comment on any questions.

Hi I have one yql query and i want that i pass variable in that query here is an example.This is a yql query and i want that the tr[1] value could be changed using varibale n whose value could be 1,2,3,4,5...n

select * from html where url="http://afghanskills.com/all-jobs.php" and xpath="//tbody/tr[1]/td/font"

Is that possible.

1 Answer

Accepted Answer

Yea, this is pretty straight forward javascript:

var win = Ti.UI.createWindow({
    backgroundColor: '#13386c'
});
 
var lbl = Ti.UI.createLabel({
    text:''
});
win.add(lbl);
 
var n = 1;
var q = 'select * from html where url="http://afghanskills.com/all-jobs.php" and xpath="//tbody/tr['+n+']/td/font"';
Ti.Yahoo.yql(q,function(e) {
    lbl.text = JSON.stringify(e.data);
});
 
win.open();

— answered 7 months ago by Anthony Decena
answer permalink
3 Comments
  • Hi I want to just ask one more question that i want to give url alsi in variable Thanks for answer

    — commented 7 months ago by Muhammad Wahhab Mirza

  • cmon now, its almost exactly as what I just showed you, with the url replaced like n was replaced:

    var n = 1;
    var url = "http://afghanskills.com/all-jobs.php";
    var q = 'select * from html where url="'+url+'" and xpath="//tbody/tr['+n+']/td/font"';

    — commented 7 months ago by Anthony Decena

  • Hi Thanks very much for this information i would be giving u 100 votes if i could

    — commented 7 months ago by Muhammad Wahhab Mirza

Your Answer

Think you can help? Login to answer this question!