Docs/Features
XML Request Body
When a request arrives with a Content-Type of text/xml, application/xml or an application/*+xml type such as SOAP 1.2's application/soap+xml (matched case-insensitively, parameters such as charset ignored), Alado automatically parses the raw body into a plain JavaScript object before your handler runs — no configuration needed, and no external XML library involved. req.body behaves the same way it does for JSON requests.
Available since v2.6.0.
How the conversion works
- Elements become object keys. Each XML tag becomes a key in the resulting object, with its children nested underneath.
- Repeated sibling tags collapse into an array.
<item>a</item><item>b</item>becomesitem: ['a', 'b']rather than overwriting the key. - Leaf elements become plain strings.
<name>Daniel</name>becomesname: 'Daniel'— no wrapper object, no type coercion (numeric-looking text like"10000.00"is kept exactly as written, since silently converting it to a JS number would lose precision on monetary values). - Attributes are namespaced under
@attrs. An element like<amount currency="USD">100</amount>becomes{ '@attrs': { currency: 'USD' }, '#text': '100' }, keeping attribute data separate from element data and text content. - Text next to child elements is kept under
#text.<p>Total: <b>5</b> EUR</p>becomesp: { b: '5', '#text': 'Total: EUR', '@ns': null }(the text pieces, joined). Whitespace used only for indentation is dropped. - Entities are decoded:
<>&"'and numeric references (A,A). A reference to a character XML does not allow (�and other control characters, a lone surrogate such as�,) gets400 Invalid XML body. - An attribute appears once per element.
<r a="1" a="2"/>gets400 Invalid XML body, as XML requires. - CDATA sections are unwrapped automatically, and their contents treated as plain text.
- One root element. Text before it, or anything after it other than whitespace and comments, gets
400 Invalid XML body. Error messages give the position of the problem, never a piece of the request. - Namespaces resolve to local names. For SOAP envelopes or ISO 20022 style payment messages, elements are keyed by their local name regardless of which prefix the sender used (
soapenv:Bodyandsoap:Bodyparse identically if they share a namespace). Each element also carries an@nsfield with its resolved namespace URI, so elements sharing a local name across different namespaces stay distinguishable.
Because the contract is identical to JSON, everything documented under defineRequest and DTOs — @validateProperty, @documentProperty, @transformProperty, auto-generated OpenAPI schemas applies to XML bodies without any extra setup.