Answer the question
In order to leave comments, you need to log in
Node.js: stream (sax.js) - data loss in file streaming?
Greetings.
Worked with xml files using xml2js until I had to work with large files.
Having looked through the Internet, I decided to use sax and saxpath for these purposes .
But here, when processing some files, a new problem arose: "Unexpected close tag"
events.js:72 thrower
; // Unhandled 'error' event
^
Error: Unexpected close tag
Line: 819060
Column: 36
Char: >
at error (d:\js\node_prog\xml_parse\node_modules\sax\lib\sax.js:652:8)
at strictFail (d:\js\node_prog\xml_parse\node_modules\sax\lib\sax.js:672:22)
at closeTag (d:\js\node_prog\xml_parse\node_modules\sax\lib\sax.js:867:7)
at Object.write (d:\js\node_prog\xml_parse\node_modules\sax\lib\sax.js:1341:29)
at SAXStream.write (d:\js\node_prog\xml_parse\node_modules\sax\lib\sax. js:227:16)
at ReadStream. (d:\js\node_prog\xml_parse\pdm_xml_2.js:36:15)
at ReadStream.EventEmitter.emit (events.js:95:17)
at ReadStream. (_stream_readable.js:745:14)
at ReadStream.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:407:10)
'use strict';
var saxpath = require('saxpath');
var fs = require('fs');
var sax = require('sax');
var saxParser = sax.createStream(true);
var streamer = new saxpath.SaXPath(saxParser, '//items/items');
streamer.on('match', function (xml) {
// do somthing with xml
// console.log(xml);
});
var xmlFileName = 'xml_files/MyFileName.xml';
function createClearString(origString) {
return origString.replace("\ufeff", "");
}
var readable = fs.createReadStream(xmlFileName);
readable.on('data', function (buf) {
buf.write(createClearString(buf.toString('utf8')));
saxParser.write(buf);
});
Line: 819060does not correspond to reality. In this file, sc symbols disappeared in the description tag (and this is 819061 lines, according to the sublime). One chunk ended with de , and the second one started with ription . I would be grateful if someone can help to understand this problem, or suggest alternatives.
Column: 36
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question