Luuka / GPXParser.js

GPX file parser javascript library
http://luuka.github.io/GPXParser.js/
MIT License
116 stars 52 forks source link

Error Handling #29

Open stelldogg opened 3 years ago

stelldogg commented 3 years ago

I'm constantly fighting this thing to take the right format file. I have a local file that I have parsed sucessfully before, but when trying to port all of my code to server and run:

let gpx = new gpxParser();
fs.readFile(gpxRecord.file, { encoding: "utf-8" }, function (error, data) {
  parser.parseString(data, function (err, res) {
    if (err) console.log(err);

    console.log(res.gpx);
    gpx.parse(res.gpx);
    console.log("Found " + gpx.tracks.length + " tracks");
  });
});

The code above never shows any tracks.

Any tips on locating errors when parsing this thing?

Luuka commented 3 years ago

Hello,

I don't know from where come the parser.parseString function but you shouldn't need it. fs.readFile already return a string that should be directly parsed.

let gpx = new gpxParser();
fs.readFile(<YourFilePath>, { encoding: "utf-8" }, function (error, data) {
    gpx.parse(data);
    console.log("Found " + gpx.tracks.length + " tracks");
});
stelldogg commented 3 years ago

Hi Luuka - I did eventually get it to work. Thanks for the response. I was asking more in terms of some info regarding the success of the call to gxp.parse(<data>).

sutarmin commented 2 years ago

hey, @Luuka thanks for your lib! I have the same question: is there a way to determine whether parsing has finished successfully? I noticed that the library just stops parsing when an unexpected tag happens and I didn't find a way of ensuring that the whole file was parsed.