Design discussion from 2026-08-12, not yet implemented. Recorded here so the reasoning survives until it's actually built. See DESIGN.md for how the current (closed) dispatch works.
Two related problems, both stemming from the same root cause:
- Issue #52: Google's
gx:namespace adds several elements (gx:Track,gx:MultiTrack,gx:Tour,gx:LatLonQuad, ...) that aren't worth fully modeling as their own case classes (see the #29 discussion — no real file to verify a specialist implementation against, soGenericElementis the right default treatment for now). - The general case: KML (or any format) keeps evolving, and a consumer of this library will
always encounter some element XmlDoc doesn't model yet. Today, an unrecognized tag inside a
polymorphic
Seq[Feature]/Seq[Geometry]is silently dropped —orderedMultiExtractor's lookup table just filters it out (see theKmlSamplesFuncSpectest titled "...silently skip the unsupported Schema element"). That's lossy, and a library consumer has no way to intervene short of forking the library.
The fix for both is the same: make "not one of the built-in subtypes" a first-class, non-lossy
outcome (fall back to GenericElement, don't drop the data), and make that fallback overridable
by a consumer who wants a real, custom typed extractor/renderer for a specific tag instead — without
forking XmlDoc.
Each closed, sealed-trait-like abstraction (Feature, Geometry, StyleSelector,
AbstractView, ...) gets one additional member wrapping a GenericElement, e.g.:
case class UnknownFeature(element: GenericElement) extends Feature
case class UnknownGeometry(element: GenericElement) extends GeometryThis is what an unrecognized tag becomes, instead of vanishing. Behavior change, on purpose:
double check KmlSamplesFuncSpec's "silently skip the unsupported Schema element" test (and any
other test relying on today's silent-drop) still makes sense once "unknown" means "captured
generically," not "gone."
Generalizes the TagProperties pattern (already used for field-level tag aliases/must-match) up
to whole-subtype dispatch: a mutable tag -> Extractor[T] registry, consulted for any tag not in
the built-in compile-time list, checked before falling back to UnknownFeature/UnknownGeometry.
A consumer registers their own Extractor[GxTrack] (or whatever) once, and it takes priority over
the generic fallback for that tag — no fork required.
Extraction dispatch is already just a runtime lookup by tag string, so opening it is
straightforward. Rendering (rendererSuperN) is fundamentally different today: it dispatches via
a fixed, compile-time list of type parameters, each checked with instanceOf — e.g.
rendererSuper6[Feature, Placemark, Container, GroundOverlay, PhotoOverlay, ScreenOverlay, NetworkLink]. A type registered at runtime can't slot into that list. This needs a genuinely
different, class-keyed runtime lookup (Map[Class[_], Renderer[_]]), tried after the fixed
cases and the UnknownFeature/UnknownGeometry case.
Issue #45 (build a real scala.xml.Elem tree during rendering, instead of assembling text
character-by-character) isn't required for the above, but it's the right thing to do first,
because it substantially simplifies exactly the code the open-registry design has to touch:
- Today's
StateR/Format.formatName/doNestedRendermachinery exists purely because rendering hand-assembles indented text. If everyRenderer[T]instead produced ascala.xml.Elem/NodeSeq, combining a fixed-dispatch case with an open-registry fallback becomes "collect aSeq[Elem]," withscala.xml's own tree composition and pretty-printer handling formatting — no bespoke padding/indent logic left to get wrong when adding a new fallback branch. - Bigger structural win:
GenericElement/GenericText/GenericCDatacurrently exist as a hand-rolled tree because rendering works in strings — they're substantially reimplementing a slice ofscala.xml.Node. With tree-based rendering, the "unknown element" fallback might not needGenericElementfor the render direction at all — just hold onto the originally-parsedscala.xml.Nodeand splice it back into the output tree unchanged. That removes a whole layer of duplicated modeling, not just some plumbing.
So: #45 doesn't solve the open-dispatch design by itself, but the open-registry work should land on top of it, not underneath it.
- Issue #45: rendering produces
scala.xml.Elem/NodeSeqinstead ofString. UnknownFeature/UnknownGeometry(and siblings for other hierarchies as needed) — verify against real files, and re-check the "silently skip" test's assumptions.- Open extraction registry (tag ->
Extractor[T]), generalizingTagProperties. - Open render registry (
Class[_] -> Renderer[T]), now straightforward given step 1. - Only then: implement
gx:Track/gx:MultiTrack/gx:Tour/gx:LatLonQuadsupport as the first real consumer of this mechanism — generic by default, overridable by anyone who wants a real typedgx:Track.
Design discussion from 2026-08-13. Motivation: Kaining's IDML three-way-merge research project
(the original reason core/idml exist at all — see DESIGN.md) is going to need a
genuine 3-way merge operation (reconcile two independent edits against a common ancestor). That's
a fundamentally different operation from what core.Mergeable[T]/.merge currently means
throughout kml — combining two adjacent, same-named things into one (e.g. two LineStrings
that share an endpoint, two Placemarks with the same name). Issue #54's own title ("merging line
strings") already used the more accurate word first: this is really a join, not a merge —
and KmlEdit.JOIN/JOINX already use exactly that term for the editing operation that calls
.merge() under the hood. Keeping "merge" for both this 2-way join operation and Kaining's
future 3-way reconciliation would be genuinely confusing once both exist side by side.
Scope, if we do this — it's bigger than it first looks:
core.Mergeable[T](the trait itself) and its companion helpers:mergeSequence,mergeOptions,mergeOptionsBiased,mergeStrings,mergeStringsDelimited. (joinOrdered, added for #54, is already named correctly and needs no change.)- Every
.mergeimplementation acrosskml:Text,Coordinate,Coordinates,GeometryData,FeatureData,LineString,Placemark, and others — dozens of call sites in both main and test sources. coreis already published to Maven Central (1.1.0) — renamingMergeable[T]/.mergethere is a real breaking API change for anyone depending onxmldoc-core, not a cosmetic rename.
Open decision, worth making deliberately rather than assuming: does the rename need to touch
core.Mergeable itself, or only kml's usage/vocabulary? Kaining's 3-way merge might end up
living entirely in idml with its own name regardless (e.g. ThreeWayMerge/reconcile), in which
case renaming kml's 2-way operation to join/Joinable — possibly without renaming core's
underlying trait, or by adding a join alias alongside merge — could resolve the confusion
without breaking core's published API at all. Worth revisiting once Kaining's own design is
concrete enough to know what vocabulary it actually needs, rather than renaming twice.
Context for why this matters as much as it does: the KML "join" functionality (KmlEdit.JOIN)
was, by Robin's own account, the original motivating reason for doing any of the kml-module
work in this project at all — Google Maps' KML export UI tends to fragment a single logical route
into dozens of separate Placemark/LineString pairs (e.g. "Historic New England Railroads
(North).kml"), and the goal was a reliable, semi-automatic way to stitch them back into correct,
contiguous lines. Issue #54's fix is the thing that actually finishes that original goal.