XML to Base64 Encoder Online — Encode XML

Validate XML, encode through UTF-8, output as standard Base64 (W3C base64Binary) or URL-safe Base64url — built for SOAP attachments, MTOM/XOP packaging, embedding XML in JSON fields, and data URLs.

What is an XML to Base64 encoder?

An XML to Base64 encoder validates an XML document, encodes it as UTF-8 bytes, and converts those bytes into an ASCII-safe Base64 string. The output is suitable for any transport that cannot carry raw XML markup — JSON string fields, HTTP headers, message-bus envelopes, SOAP's base64Binary type, and data: URLs.

The two output flavours match different transports. Standard Base64 uses +, /, and = padding — required by SOAP's base64Binary, MTOM/XOP, and most enterprise systems. URL-safe Base64url swaps + for - and / for _ with padding stripped, ideal for query strings and filenames.

How to encode XML to Base64 — 4 steps

  1. Paste XML. A complete document or fragment with declaration, namespaces, and CDATA preserved. Click Load Sample for a SOAP envelope demo.
  2. Pick the variant. Standard Base64 (default) for SOAP/MTOM and HTTP bodies. URL-Safe (Base64url) for URLs and tokens.
  3. Click Encode. DOMParser validates well-formedness, the document is UTF-8 encoded, and Base64 is produced.
  4. Copy. Drop the Base64 directly into a JSON field, a SOAP base64Binary element, or a data URL.

Sample input and output

XML input

<note>
  <to>Bob</to>
  <from>Alice</from>
  <body>Hello!</body>
</note>

Base64 output (standard)

PG5vdGU+CiAgPHRvPkJvYjwvdG8+CiAg
PGZyb20+QWxpY2U8L2Zyb20+CiAgPGJv
ZHk+SGVsbG8hPC9ib2R5Pgo8L25vdGU+

Validate Before Encoding

DOMParser confirms the XML is well-formed first — no risk of producing Base64 that decodes back to broken markup.

SOAP base64Binary Ready

Default standard Base64 output matches the W3C XML Schema base64Binary type required by SOAP and MTOM.

URL-Safe Toggle

One click switches to Base64url with - / _ and stripped padding for safe embedding in URLs and filenames.

Common use cases

  • check_circleEncoding XML attachments for SOAP with Attachments (SwA) and MTOM/XOP packaging
  • check_circleEmbedding XML payloads as Base64 strings inside JSON API fields
  • check_circleStoring XML documents as Base64 in SQL Server varbinary or Oracle BLOB columns
  • check_circleEncoding XML for transmission over message buses (Kafka, SQS, RabbitMQ) that prefer ASCII payloads
  • check_circleProducing data URLs (data:application/xml;base64,...) for inline XML resources
  • check_circleEncoding XML SAML assertions for Base64-wrapped SSO callbacks
  • check_circleWrapping HL7 v2 / FHIR XML in Base64 for legacy healthcare integrations
  • check_circleEncoding XML config files for cloud secret managers that require ASCII values

XML to Base64 vs raw text Base64

A generic Base64 encoder accepts any input, including malformed XML. The receiving SOAP runtime then rejects the decoded payload at the worst possible moment. This encoder validates with DOMParser before encoding so a missing close-tag surfaces immediately. For non-XML binary content (PDFs, ZIPs, images), use a generic Base64 encoder instead.

Need to clean the XML first?

Format, validate, or convert your XML with the rest of OpenFormatter before encoding.

Frequently Asked Questions

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.

XML to Base64 Encoder Online — Encode XML | OpenFormatter