Why encode XML as Base64 instead of escaping it?
Escaping XML inside JSON requires backslash-escaping every quote, every newline, and every control character — fragile and noisy. Base64 collapses the entire document into one ASCII string that survives any text transport unchanged. The trade-off is roughly a 33% size increase, but readability and reliability win in API envelopes, message buses, and database BLOB columns.
How do I prepare an XML attachment for SOAP/MTOM?
Validate and Base64-encode the attachment XML here, then place the result inside a base64Binary element or an <xop:Include> stub in the SOAP body. The receiving runtime extracts the binary and reconstructs the attachment. Pair this tool with the Base64 to XML decoder for round-trip testing.
Should I use URL-safe Base64url for SOAP attachments?
No. SOAP base64Binary expects standard Base64 (+, /, = padding) per the W3C XML Schema spec. URL-safe Base64url is for URL parameters and JWT-style tokens — toggling it for SOAP will cause schema validation failures on the receiving side.
Why is XML validated before encoding?
A typo in the XML — an unclosed tag, a stray < — would produce Base64 that decodes back to broken XML. Validating first via DOMParser surfaces the issue immediately so the encoded payload is always round-trip safe.
How big can the XML be before encoding fails?
btoa works on strings of any size your tab can hold, but very large documents (>10 MB after Base64 expansion) may slow the browser. For multi-megabyte SOAP attachments consider gzipping before Base64 — encode the gzipped bytes outside the browser to keep the round-trip fast.
Will the encoded Base64 fit in a JSON string field?
Yes. Standard Base64 only contains A-Z a-z 0-9 + / = — all of which are valid inside a JSON string with no escaping. You can paste the output directly between quotes in a JSON field.
Does this preserve the XML declaration and namespaces?
Yes. The encoder preserves the XML byte-for-byte, including the <?xml version="1.0"?> prolog, namespace declarations, prefixed elements, and CDATA sections. The decode round-trip yields identical bytes.
Is the XML uploaded to your servers?
No. Validation, UTF-8 encoding, and Base64 conversion all happen in your browser via DOMParser and btoa. SOAP envelopes carrying account numbers, tokens, or PII stay on your machine — verify in DevTools Network tab.