Expand description
SOAP/XML protocol translation (DW-100).
The SoapTranslator implements super::translation::ProtocolTranslator
for routes that bridge a REST/JSON client and a SOAP/XML upstream (or
vice versa). Two directions:
- SOAP-to-REST (
kind: soap_to_rest): the client sends a SOAP XML envelope; the translator parses the envelope, extracts theBody’s first child element (the operation), and converts its XML children to a JSON body the REST upstream expects. - REST-to-SOAP (
kind: rest_to_soap): the upstream returns a REST JSON body; the translator wraps it in a SOAP envelope (Envelope > Body > {operation}) with the configured operation name and namespace, converting the JSON to XML.
§Minimal XML parser
A full XML library would be a new dependency (and a deny.toml review). SOAP envelopes are a narrow XML subset: elements with optional attributes, text content, and nested elements – no DTDs, no entity expansion, no processing instructions. A minimal hand-rolled parser handles that subset and rejects everything else (fail-closed against anything it cannot prove well-formed). The parser is bounded: a depth cap prevents element-nesting DoS, and a size cap rejects oversized bodies before parsing.
§XML <-> JSON convention
The conversion follows a simple, deterministic convention:
- An element with only text content -> a JSON string (or number/bool when the text parses as one).
- An element with child elements -> a JSON object mapping each child tag to its converted value. Repeated child tags become a JSON array.
- Attributes -> a
@attrkey in the object.
This is sufficient for SOAP body payloads (which are flat-ish data records); complex XSD types are out of scope for the hand-rolled converter.
§Feature gating
Compiled under the soap cargo feature (which implies
protocol_translation).
Structs§
- Soap
Translator - The SOAP-to-REST / REST-to-SOAP translator.
- XmlElement
- A parsed XML element: name (qualified, prefix retained), attributes, and children (elements and text).
Enums§
- Soap
Direction - The translation direction.
- XmlChild
- One child of an XML element: a nested element or a text run.