提及它的文档 scala.xml.pull.XMLEventReader
可以用作Iterator[XMLEvent]
. 但是,这样做时,XML 错误会导致方法调用未终止。例如:
scala> new xml.pull.XMLEventReader(io.Source.fromString("<a><b></a>")).toArray
Exception in thread "XMLEventReader" scala.xml.parsing.FatalError: expected closing tag of b
at scala.xml.parsing.MarkupParser$class.errorNoEnd(MarkupParser.scala:41)
at scala.xml.pull.XMLEventReader$Parser.errorNoEnd(XMLEventReader.scala:56)
at scala.xml.parsing.MarkupParserCommon$class.xEndTag(MarkupParserCommon.scala:93)
at scala.xml.pull.XMLEventReader$Parser.xEndTag(XMLEventReader.scala:56)
at scala.xml.parsing.MarkupParser$class.element1(MarkupParser.scala:543)
at scala.xml.pull.XMLEventReader$Parser.element1(XMLEventReader.scala:56)
at scala.xml.parsing.MarkupParser$class.content1(MarkupParser.scala:396)
at scala.xml.pull.XMLEventReader$Parser.content1(XMLEventReader.scala:56)
at scala.xml.parsing.MarkupParser$class.content(MarkupParser.scala:417)
at scala.xml.pull.XMLEventReader$Parser.content(XMLEventReader.scala:56)
at scala.xml.parsing.MarkupParser$class.element1(MarkupParser.scala:542)
at scala.xml.pull.XMLEventReader$Parser.element1(XMLEventReader.scala:56)
at scala.xml.parsing.MarkupParser$class.content1(MarkupParser.scala:396)
at scala.xml.pull.XMLEventReader$Parser.content1(XMLEventReader.scala:56)
at scala.xml.parsing.MarkupParser$class.document(MarkupParser.scala:216)
at scala.xml.pull.XMLEventReader$Parser.document(XMLEventReader.scala:56)
at scala.xml.pull.XMLEventReader$Parser$$anonfun$run$1.apply(XMLEventReader.scala:90)
at scala.xml.pull.XMLEventReader$Parser$$anonfun$run$1.apply(XMLEventReader.scala:90)
at scala.xml.pull.ProducerConsumerIterator$class.interruptibly(XMLEventReader.scala:113)
at scala.xml.pull.XMLEventReader.interruptibly(XMLEventReader.scala:26)
at scala.xml.pull.XMLEventReader$Parser.run(XMLEventReader.scala:90)
at java.lang.Thread.run(Thread.java:680)
这个调用永远不会终止。我们在这里看到解析异常被打印,但它似乎没有中断对toArray
. 这似乎是因为实际的解析发生在一个单独的线程中,该线程被终止,但是错误永远不会报告给调用线程(这在问题 SI-4267 中有描述)。是否有可能以某种方式在调用线程上重新引发这些异常?甚至打算使用这个类,还是我应该使用另一个拉解析器?