xml - Parse.com Cloud Code Evaluate xPath? -


i new using parse.com cloud code, , ios developer. in ios use hpple, xpath evaluator parse xml document. need in cloud code. wondering if there way in javascript sdk expressions like

xpath expression:

//day[@name='monday']/meal[@name='lunch']/counter[@name='deli']/dish/name 

to evaluate xml url:

http://64.182.231.116/~spencerf/union_college/upperclass_sample_menu.xml 

this return strings "made order deli core", "caprese panini biggie sandwich". there way in javascript sdk or there modules can install parse's cloud code can evaluate xml this?

the code have tried far this:

parse.cloud.define("next", function(request, response) {    var xmlreader = require('cloud/xmlreader.js');    parse.cloud.httprequest({     url: 'http://64.182.231.116/~spencerf/union_college/upperclass_sample_menu.xml',     success: function(httpresponse) {         //console.log(httpresponse.text);         var somexml = httpresponse.text;          xmlreader.read(somexml, function (err, res){             if(err) return console.log(err);              // use .text() content of node:             console.log( res.dish.text() );          });      },     error: function(httpresponse) {         console.error('request failed response code ' + httpresponse.status);     }   });   }); 

i can data saved in variable somexml, think saved string, maybe messing parsing because unable parse it. using xmlreader parse (https://www.npmjs.org/package/xmlreader) there link how works , syntax parsing. having trouble parsing though. ideally parse xpath using code:

    var getelementbyxpath = function (path) {   return somexml.evaluate(path, somexml, null, 2, null).stringvalue;    };   console.log(getelementbyxpath("//day[@name='monday']/meal[@name='lunch']/counter[@name='deli']/dish/name")); 

but not working, gave me error

has no method 'evaluate' @ getelementbyxpath (main.js:131:20) @ object.parse.cloud.httprequest.success (main.js:134:17) @ object.<anonymous> (<anonymous>:571:19) 

on link provided name nodes under monday/lunch

this right here

xmlreader.read(somexml, function (err, res){ if(err) return console.log(err); for(var = 0; < res.day.count(); i++){   if (res.day(i).text()) == "monday")   {     for(var j = 0; j < res.day(i).meal.count(); j++){       if (res.day(i).meal(j).text() == "lunch")       {         for(var k = 0; k < res.day(i).meal(j).counter.dish; k++){           console.log( res.day(i).meal(j).counter.dish(k).name.text());         }       }     }  } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -