3 ms·
Lately I've been having some luck with using parser combinators to parse XML in OCaml. I just define a lazy list type that takes input from Xmlm's streaming dec
by steinuil 7y ago
Lately I've been having some luck with using parser combinators to parse XML in OCaml. I just define a lazy list type that takes input from Xmlm's streaming decoder and a few parsers for xml elements (`data : string parser` and `el : string -> 'a Attr.parser -> 'b parser -> ('a * 'b) parser`), plus all the usual combinators. It's probably not as fast as using libxml2 but at least it's type safe.
EDIT: The Attr.parser above uses the same combinators but it operates on a simple list of Xmlm attributes using a function that takes an attribute name and returns the value of that attribute, if found, and the list without that attribute.