Ragnarok: An Experimental XML environment
Steven J. DeRose · Balisage series on markup technologies · 2025
XML has a highly reliable, consistent, widely-supported ecosystem. Python is enormously popular, yet (perhaps surprisingly) its support for XML has weaknesses. Several parsers are available but most (including the “official” xml.parsers.expat) are not native Python, leading to issues with Python development tools. The Python DOM library (xml.dom.minidom) is native, but is barely DOM 2.0, slow, and lacks conveniences well-established elsewhere. It is also not “Pythonic,” using few modern Python features and idioms. lxml is admirably Pythonic for Elements, but text poses problems. Ragnarok is a new, pure Python XML tool suite that addresss these issues. It provides plug-compatible replacements for Python XML libraries, and is equipped with many Pythonic conveniences (the “batteries included” philosophy of Python). The parser ( Thor ), uses recursive decent: methods map directly to the XML grammar, easing debugging and extension. A validator ( Heimdall ) is in progress. Schemera handles DTDs, but its architecture is more like XML Schema. The DOM library ( Dominµs , aka Yggdrasil ) is much faster than minidom, with almost all of DOM 3 Core and many features drawn from other XML and HTML tools and from Python practice. Flexible output serializing comes via components called Gleipnir and Bifrost . Non-hierarchical structures have long been of interest to this community, but face a dilemma because XML doesn’t really support them: one can coerce to XML syntax via milestones or standoff markup; or create entirely new syntax. In either case XML tools give little help. Beside Thor, Ragnarok also includes a second parser, called Loki , which explores a middle way. Loki accepts non-hierarchical structures via syntax that includes non-XML extensions, but remains so similar that (a) no prior WF XML changes meaning, and (b) the implementation is easily constructed on top of a regular parser. This may enhance data and code re-use. Loki is a subclass (rather than brother) of Thor, and like its namesake can change its shape. Loki can be configured with many XML-adjacent options ranging from case-folding names or enabling named character entities (both difficult with many other tools), on up to extensions for olists, suspend/resume, and milestone-encoded structures. Ragnarok overall can help with everyday XML tasks in Python by being faster, more up-to-date, more Pythonic, and more fully functional. On the other hand, Loki can help with overlap and a variety of other tasks at the edge.