$ show pdvrieze/xmlutil
xmlutil is a Kotlin Multiplatform XML library that provides three layers: a streaming pull-parser/writer abstraction (XmlReader/XmlWriter with a pure-Kotlin KtXmlReader and platform StAX/Android backends), a portable DOM Level 2 implementation with JVM/JS/Native/Wasm wrappers, and an XML serialization format for kotlinx.serialization (the XML.v1 codec with annotations such as @XmlSerialName, @XmlValue, @XmlPolyChildren and policy-based configuration). It is a library, not an application: there are no servers or CLIs, only published Maven artifacts (core, serialization, xmlschema, serialutil, testutil) plus examples, benchmarks, and a Gradle plugin used for building/publishing the library itself. It targets JVM, Android (deprecated module), JS, Native, and Wasm. The architecture is strictly modular: core/base holds platform-independent streaming, DOM, namespaces, and entity handling; core/jdk and core/android are platform backends; serialization implements the kotlinx.serialization format including type/descriptor caching, polymorphic parent handling, and compact-fragment support; xmlschema is a near-complete XML Schema 1.0/1.1 parser/resolver with a custom XPath expression engine and a purpose-built regex engine for XSD pattern facets; serialization-io and core/kxio bridge kotlinx-io sinks/sources; testutil ships cross-platform XML assertion helpers. The dominant data flow is: XML text -> streaming events (XmlReader) -> DOM or direct object deserialization, and the reverse for output, with XmlSerializationPolicy controlling naming, lists, maps, namespaces, and encoding/decoding behavior. The engineering depth is genuinely high: a hand-written XSD regex engine with Unicode decomposition and surrogate set classes, flat-array namespace stacks with O(1) depth operations, DTD/entity expansion logic, an LRU format cache with recursion detection, and binary-compatibility validation (API and klib .api files) on every build. Test coverage is extensive, including regression tests for dozens of numbered GitHub issues, a W3C XML Schema test-suite harness, and JVM benchmarks. The main weaknesses are an intentionally large experimental API surface (@ExperimentalXmlUtilApi), some boilerplate near-duplication in schema facet classes, and platform-source-set sprawl that multiplies maintenance cost. Maintenance is active: recent commits (Aug 2026), GitHub Actions CI (runTests, publish-snapshot, upload_release), zero Dependabot alerts, and modern tooling (Gradle version catalog, BOM, Gradle wrapper validation). Some legacy artifacts remain (stale .travis.yml, deprecated core-android and xmlserializable modules), but they are explicitly marked deprecated rather than silently rotting. Technical drift is low; the codebase deliberately tracks fast-moving kotlinx.serialization APIs and documents Kotlin compiler workarounds, indicating a maintained rather than abandoned project.
The LLM identified 5 files worth highlighting for reuse:
A namespace-context stack implemented with flat arrays to achieve O(1) push/pop at each element depth, avoiding per-element allocation. This is the backbone of namespace-aware XML readers/writers and is self-contained enough to extract into any streaming XML parser that must track prefix mappings across nesting levels.
A generic thread-safe LRU cache reused by DefaultFormatCache to memoize XML serial descriptors. It adds pending-descriptor tracking so mutually recursive type descriptors resolve without deadlock or infinite recursion, a non-obvious refinement over plain LRU maps. The generic core can be lifted into any project needing bounded, concurrency-safe memoization with re-entrant key resolution.
A self-contained RFC 3986 URI parser written as a state machine rather than platform regex, so it runs identically on JVM, JS, Native, and Wasm. It exists to validate XSD anyURI values but is a clean, extractable multiplatform URI utility with no schema-module dependencies beyond its own value classes.
Cross-platform XML equality assertion that normalizes document declarations, namespace prefix choices, and attribute ordering so tests pass across JVM, JS, and Native DOM implementations. Published as a standalone testutil artifact specifically so downstream Kotlin multiplatform projects can reuse a non-trivial testing pattern (structural XML comparison) that is surprisingly hard to get right.
Turns a standalone XML fragment (e.g. a single element with no prolog) into a valid event stream by wrapping it in a synthetic root element and transparently stripping that root from the emitted events. Implemented across JVM/JS/Native variants, demonstrating a portable, documented technique for fragment round-tripping that transfers directly to any streaming XML API.