Node xml2js returns 'undefined' when using parseString ()

I use this package elsewhere and it works fine, however, in one specific example with a single XML file, I get "undefined" errors.

Example:

fs.readFile('./XML/theXMLfile13mb.xml', 'ascii', function(err,data){
    if(err) {
        console.log("Could not open file " + err);
        process.exit(1);
    }

    parseString(data, function (err, result) {
        console.log(result); // Returns undefined
        var json1 = JSON.stringify(result); // Gives an error
        var json = JSON.parse(json1);

xml2jsdocs don't really mention how this could be possible / what it might mean. I tried using other XML files and they work great. This particular XML file is no bigger than the others, and it doesn't seem to be less tactful (it opens perfectly in my browser and all the data is presented as expected).

Any ideas on how I can fix this problem?

+4
source share
1 answer

data , :

parseString(data.toString(), function (err, result) {

:

parseString(data, function (err, result) {
0

All Articles