- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Why does this not terminate?
Wed, 2009-04-29, 01:44
The following works exactly as I would expect until the end of the XML
file. When it is done, er.hasNext blocks, waiting for...something,
instead of returning false.
1) why???
2) is there a different way I should be iterating through the events?
for (evt <- er ) does the same thing, of course.
package foo.bar
import scala.xml._
import scala.xml.pull._
import scala.io.Source
object TestParse {
def main(args : Array[String]) : Unit = {
val src = Source.fromFile("test.xml")
val er = new XMLEventReader().initialize(src);
while (er.hasNext) {
println(er.next)
}
}
}
On Tue, Apr 28, 2009 at 05:44:13PM -0700, Tupshin Harper wrote:
> The following works exactly as I would expect until the end of the XML
> file. When it is done, er.hasNext blocks, waiting for...something,
> instead of returning false. 1) why???
Let's take a look at the ol' hasNext implementation:
def hasNext = true
Not so good for a while loop. However that is indeed the ol'
implementation as I checked in a whole new parser today and now it is:
def hasNext() = !eos && (buffer != null || fillBuffer)
Please try out the parser and let me know if it does good things (I
imagine tonight's nightly build will have it.) I give my hasNext a
slightly better chance of terminating, but one can never be too sure
when it comes to halting problems.