Documentation
¶
Overview ¶
Package xmlx is a mvm-aware shim for the encoding/xml functions that must honour xml.Unmarshaler methods (UnmarshalXML) defined on interpreted types. Native encoding/xml reflects over a synthetic native rtype for an interpreted type whose method set does not include the interpreted UnmarshalXML, so it falls back to the default codec (e.g. decoding the CharData "gopher" into the int underlying type). This shim re-implements just enough of the decode walk to reach interpreted custom unmarshalers, delegating every pure-native subtree wholesale to the native xml.Decoder.
Dispatch is wired through vm.RegisterArgProxy: the second argument to xml.Unmarshal is wrapped as an *unmarshalProxy whose UnmarshalXML re-enters the walker with full Iface metadata. Native encoding/xml reflection sees the proxy as an ordinary xml.Unmarshaler.
The proxy is installed only when the destination type transitively contains an interpreted UnmarshalXML (see containsCustom); otherwise the argument falls back to default any-bridging and native xml handles it exactly as before. This keeps pure-native decoding byte-identical to the native bridge. Mirrors stdlib/jsonx and stdlib/gobx.
Not yet handled in a hand-walked (custom-bearing) struct: ",attr" fields, nested-path tags ("a>b>c"), ",chardata"/",cdata"/",comment"/",innerxml", and the encode direction (xml.Marshal). Those subtrees are only walked when they sit alongside a custom unmarshaler; pure-native structs using them are delegated whole and keep working.