3

I need to parse an XML/HTML file within the cloud-code of parse.com.

I've got a string which contains the source-code of the html file.

I've already tried multiple frameworks like jsdom etc, but nothing seems to work in the Parse.com-cloudcode environment.

This code for example results in an error in the jsdom-file. But I've got no idea what the real problem is. Because the "<" ">" tags are set correctly in the jsdom.js-file.

var jsdom = require("cloud/jsdom.js");
var window = jsdom.jsdom().createWindow();
var jquery = require("cloud/jquery-1.11.2.min.js")(window);

var dataHtml = httpResponse.text;

response.success(jquery.$(dataHtml).find("body").text());

Error:

{"code":141,"error":"Error: Uncaught SyntaxError: Unexpected token \u003c in jsdom.js:5\n    at Object.Parse.Cloud.httpRequest.success (main.js:9:21)

Is there another possibility to parse a string with XPath or dom in the parse.com-cloudcode?

1 Answer 1

6

This answer can be too late, but I just realized a bundle of cheerio module that works with Parse.

Example:

var cheerio = require('cloud/cheerio.bundle.js'),
    $ = cheerio.load('<h2 class="title">Hello world</h2>');

$('h2.title').text('Hello there!');
$('h2').addClass('welcome');

$.html();
//=> <h2 class="title welcome">Hello there!</h2>

You can get it here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.