robrighter / node-xml

An xml parser for node.js written in javascript.
197 stars 59 forks source link

No way to detect incomplete document #21

Open JasonWoof opened 12 years ago

JasonWoof commented 12 years ago

There doesn't seem to be any way to specify that parseString() will not be called again (end of input.)

Thus there seems to be no way to detect an incomplete document. I'm getting xml over http, and I don't want my app to hang forever waiting for xml parsing if I get an incomplete document over http.

When I remove the last parseString call from example.js it does call endDocument at the end, but it also calls it 4 other times, so it's unusable.

Here's what I want: a second parameter to parseString (boolean) that says whether this is the final hunk or not.

If I specify that it's the final hunk, the onError event will fire if the document hasn't closed all the nodes or whatever.

Thanks!

JasonWoof commented 12 years ago

Note that if I concatenate all the parseString() args in example.js and call parseString() once like this:

parser.parseString("<html><body>"
+ "<!-- This is the start"
+ " and the end of a comment -->"
+ "and lots"
+ "and lots of text&am"
+ "p;some more."
+ "<![CD"
+ "ATA[ this is"
+ " cdata ]]>"
+ "</body"
+ "></html>"
);

But if you comment out the ></html> line, no endDocument or Error or anything fires.