prewk / xml-string-streamer

Stream large XML files with low memory consumption.
MIT License
356 stars 49 forks source link

Some trouble when XML is not fully valid #38

Closed jedi2209 closed 9 years ago

jedi2209 commented 9 years ago

Method $streamer->getNode() freeze when XML file is not valid. For example, not fully uploaded on server. I couldn't find chance to check huge file for validity before parse it.

prewk commented 9 years ago

Hm, interesting that it froze, I thought a more realistic scenario would be that it crashed and burned or something instead.

Please get back to me if you can reproduce it with some XML file. I wouldn't really say XML validity checks is within the scope of this package, but it's better if it's a controlled crash instead of freezing up.

jedi2209 commented 9 years ago

Yeah, it will be great, if it controlled crashed or makes some error, but it only froze. Here is my code:

$stream = new Prewk\XmlStringStreamer\Stream\File($file, 1024); $parser = new Prewk\XmlStringStreamer\Parser\StringWalker(array("captureDepth" => 4)); $streamer = new Prewk\XmlStringStreamer($parser, $stream); while ($node = $streamer->getNode()) { $row_node = simplexml_load_string($node); /* some to do */ }

And here i make some problem file - https://yadi.sk/d/QLprfuvYgVBUA

prewk commented 9 years ago

Great, I'll have a look at it as soon as I have time for it!

prewk commented 9 years ago

Fixed in 0.7.1 (dunno why Travis refuses to build it, though, works locally for me)

edit: Yay, now it builds

prewk commented 9 years ago

Oh, I should probably mention: I made the decision to not throw an exception/fail.. the parsers just go until they're unable to parse any further, then they consider the stream to be finished.