Jump to content

Getting a Error: Non-whitespace before first tag in Node.js

I am accessing an online api to get xml file with many ids.

This is my code

var https = require('https');
var xml2js = require('xml2js');
var parser = new xml2js.Parser({optionName: 'normalize'});
var concat = require('concat-stream');

parser.on('error', function(err) { console.log('Parser error', err); });

https.get("https://www.leaksapi.com/clinton-emails/from/<APIKEY>/Hillary%20Clinton", function(resp) {

    resp.on('error', function(err) {
      console.log('Error while reading', err);
    });

    resp.pipe(concat(function(buffer) {
      var string = buffer.toString();
      var cleanedString = string.replace("\ufeff", "");
      parser.parseString(cleanedString, function(err, result) {
        console.log('Finished parsing:', err, result);
      });
    }));

});

And I keep on getting an Error: Non-whitespace before first tag. Even when I have cleared the first non-whitespace character in the line var cleanedString.

Parser error Error: Non-whitespace before first tag.
Line: 0
Column: 1
Char: [
    at error (C:\Users\Snama\node_modules\sax\lib\sax.js:642:8)
    at strictFail (C:\Users\Snama\node_modules\sax\lib\sax.js:662:22)
    at Object.write (C:\Users\Snama\node_modules\sax\lib\sax.js:935:11)
    at Parser.exports.Parser.Parser.parseString (C:\Users\Snama\node_modules\xml2js\lib\xml2js.js:508:31)
    at Parser.parseString (C:\Users\Snama\node_modules\xml2js\lib\xml2js.js:7:59)
    at C:\Users\Snama\Documents\DonaldTrumpPropaganda\webreader.js:17:14
    at ConcatStream.<anonymous> (C:\Users\Snama\node_modules\concat-stream\index.js:36:43)
    at emitNone (events.js:91:20)
    at ConcatStream.emit (events.js:185:7)
    at finishMaybe (C:\Users\Snama\node_modules\concat-stream\node_modules\readable-stream\lib\_stream_writable.js:475:14)

What am I doing wrong. Thanks

I like potatoes, if you don't then please just step aside and let me enjoy this potato.

Link to comment
Share on other sites

Link to post
Share on other sites

Hey its you again xD,

Looks like I am just dumb and it happens to be a json reply.

I like potatoes, if you don't then please just step aside and let me enjoy this potato.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×