Reputation: 32284
Is there an XML pull parser (similar to Java StAX) for Haskell?
I am envisioning using it with a pure function that accepts a parser. My function will call something like nextItem parser
and pattern-match on the result (StartElement
, EndElement
, Text
, EntityRef
, etc.) My function can then call itself recursively to process child elements, etc., constructing a private data structure as it traverses the XML "tree".
As I understand it, pull-parsing should have better performance than constructing an internal representation of the DOM, then traversing it, although I don't know if this is true in a lazy language.
Upvotes: 2
Views: 339
Reputation: 31315
You can use xml-conduit, which provides both streaming and full-document modules. The streaming parsing module Text.XML.Stream.Parse also provides a number of helper combinators.
It's true that if you had a truly lazy data source, there would be no (significant) performance difference between a pull parser and dealing with the lazy list. However, XML parsing usually involves I/O. conduit is designed to give you a high-level approach to these kinds of parsing issues.
Upvotes: 5