It feels terribly silly, both parsing XML in 2026 and having to ask for some help on the matter!
I've been working on a pet project of mine, a calorie counter that uses public datasets as sources. I've been making it with ZIO (and all by hand, the goal is to train after all), and one of my sources is Ciqual, 2025, made available by the French government here. It's not a large dataset, the biggest file being compo_2025_11_03.xml at 66Mo.
However, reading it with zio-schema-xml fail with various SAXParsingExceptions. Same issue when I tried DuckDB and webbed. Right now, I'm going around it by chunking the file into a stream, getting all "COMPO" elements in different elements, and parsing that. The file seems fine through xmllint and other validation tools, but I didn't find an easier way of parsing it.
Any advice? I'll probably try Pekko Streams or something latter, but I'd love to see what you'd try or if I missed something obvious.
====================================================================
Edit: Thanks everyone, for your comments and your help! Next time, I'll build a project before asking a question, it clearly was an issue for some of you!
Special thanks on top to u/fancellu for his very complete answer.
For my zio-schema-xml code, the biggest issues were thinking to write a codec for List[Compo] rather than Table or Compo.
streamCodec = XmlCodec.
schemaBasedBinaryCodec
[List[Compo]]streamCodec = XmlCodec.schemaBasedBinaryCodec[List[Compo]]
was the right "shape" for the codec. The other issue was that the file had a BOM! (I found out BOMs were a thing at the same time, UTF-8 made it more or less obsolete.) Trying to read a file as a stream of bytes (either from direct downloading, local files, or S3) made it fail very early, as the codec was looking for a starting "<" that it didn't find.
As for DuckDB, the issue was completely different. As it turns out, the XML plugin for DuckDB, Webbed, has a hidden limit to the size of files. Using read_xml() on your file gives you a SAX Parsing Error, and the actual issue was only made clear when I tried read_xml_objects(). As it turns out, you can just change that at the request level with the maximum_file_size parameter.
Sorry for the plain text explanation! fancellu put out an example for anyone interested in his zio-schema-example repo. Don't hesitate to star it there while you check it out!
I may share my repo in another edit, once I'm happy with the code quality, if anyone's interested.