partial-xml-stream-parser
Version:
A lenient XML stream parser for Node.js and browsers that can handle incomplete or malformed XML data, with depth control, CDATA support for XML serialization and round-trip parsing, wildcard pattern support for stopNodes, and CDATA handling within stopNo
40 lines • 1.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.xmlObjectToString = exports.PartialXMLStreamParser = void 0;
const parser_setup_1 = require("./src/parser-setup");
const stream_processor_1 = require("./src/stream-processor");
const core_parser_1 = require("./src/core-parser");
const utils_1 = require("./src/utils");
Object.defineProperty(exports, "xmlObjectToString", { enumerable: true, get: function () { return utils_1.xmlObjectToString; } });
class PartialXMLStreamParser {
constructor(options) {
(0, parser_setup_1.initializeParserOptions)(this, options);
this.reset();
}
reset() {
(0, parser_setup_1.resetParserState)(this);
}
_processBuffer() {
(0, core_parser_1.coreProcessBuffer)(this);
}
parseStream(xmlChunk) {
const chunkProcessingResult = (0, stream_processor_1.processXmlChunk)(this, xmlChunk);
if (chunkProcessingResult.earlyExitResult) {
return chunkProcessingResult.earlyExitResult;
}
// Only call _processBuffer if the chunk processor determined it's necessary
// and there's actually something in the streamingBuffer to process,
// or if there's an incomplete state that needs resolving even with an empty new chunk.
if (chunkProcessingResult.shouldProcessBuffer &&
(this.streamingBuffer.length > 0 || this.incompleteStructureState)) {
this._processBuffer();
}
else if (chunkProcessingResult.shouldProcessBuffer && xmlChunk === null && this.incompleteStructureState) {
// Special case for EOF with only incomplete state and empty buffer.
this._processBuffer();
}
return (0, stream_processor_1.finalizeStreamResult)(this, xmlChunk);
}
}
exports.PartialXMLStreamParser = PartialXMLStreamParser;
//# sourceMappingURL=index.js.map