Skip to content

Commit 3038a07

Browse files
committed
Merge pull request #28 from alexlatchford/master
endDocument is called even after pause/resume used
2 parents 6f62071 + 048070b commit 3038a07

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

lib/node-xml.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,33 +234,41 @@ XMLP.prototype._parse = function() {
234234
return XMLP._NONE;
235235
}
236236

237+
function _indexOf(needle, haystack, start) {
238+
// This is an improvement over the native indexOf because it stops at the
239+
// end of the needle and doesn't continue to the end of the haystack looking.
240+
for(var i = 0; i < needle.length; i++) {
241+
if(needle.charAt(i) != haystack.charAt(start + i))
242+
return -1;
243+
}
244+
return start;
245+
}
246+
237247
var fc = this.m_xml.charAt(this.m_iP);
238248
if (fc !== '<' && fc !== '&') {
239-
return this._parseText (this.m_iP);
240-
}
241-
else if(this.m_iP == this.m_xml.indexOf("<?", this.m_iP)) {
249+
return this._parseText (this.m_iP);
250+
}
251+
else if(this.m_iP == _indexOf("<?", this.m_xml, this.m_iP)) {
242252
return this._parsePI (this.m_iP + 2);
243253
}
244-
else if(this.m_iP == this.m_xml.indexOf("<!DOCTYPE", this.m_iP)) {
254+
else if(this.m_iP == _indexOf("<!DOCTYPE", this.m_xml, this.m_iP)) {
245255
return this._parseDTD (this.m_iP + 9);
246256
}
247-
else if(this.m_iP == this.m_xml.indexOf("<!--", this.m_iP)) {
257+
else if(this.m_iP == _indexOf("<!--", this.m_xml, this.m_iP)) {
248258
return this._parseComment(this.m_iP + 4);
249259
}
250-
else if(this.m_iP == this.m_xml.indexOf("<![CDATA[", this.m_iP)) {
260+
else if(this.m_iP == _indexOf("<![CDATA[", this.m_xml, this.m_iP)) {
251261
return this._parseCDATA (this.m_iP + 9);
252262
}
253-
else if(this.m_iP == this.m_xml.indexOf("<", this.m_iP)) {
263+
else if(this.m_iP == _indexOf("<", this.m_xml, this.m_iP)) {
254264
return this._parseElement(this.m_iP + 1);
255265
}
256-
else if(this.m_iP == this.m_xml.indexOf("&", this.m_iP)) {
266+
else if(this.m_iP == _indexOf("&", this.m_xml, this.m_iP)) {
257267
return this._parseEntity (this.m_iP + 1);
258268
}
259269
else{
260270
return this._parseText (this.m_iP);
261271
}
262-
263-
264272
}
265273

266274
////////// NAMESPACE SUPPORT //////////////////////////////////////////
@@ -839,10 +847,15 @@ SaxParser.prototype.pause = function() {
839847
SaxParser.prototype.resume = function() {
840848
//reset the state
841849
this.m_parser.resume();
850+
this.m_interrupted = false;
851+
842852
//now start up the parse loop
843853
var that = this;
844854
setTimeout(function(){
845855
that._parseLoop();
856+
if(!that.m_bErr && !that.m_interrupted) {
857+
that._fireEvent(SaxParser.DOC_E);
858+
}
846859
}, 0);
847860
}
848861

0 commit comments

Comments
 (0)