Format SOAP XML Messages — Envelope, Header, and Body
Format and pretty-print SOAP XML messages. Understand the SOAP Envelope structure, namespaces, Header and Body elements, and how to read complex SOAP request/response payloads.
Detailed Explanation
Formatting SOAP XML
SOAP (Simple Object Access Protocol) messages are XML documents with a specific structure: an Envelope element containing optional Header and required Body elements. Formatting SOAP XML makes these deeply nested, namespace-heavy messages readable.
SOAP Envelope Structure
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ws="http://example.com/webservice">
<soap:Header>
<ws:AuthToken>abc123</ws:AuthToken>
</soap:Header>
<soap:Body>
<ws:GetUserRequest>
<ws:UserId>42</ws:UserId>
</ws:GetUserRequest>
</soap:Body>
</soap:Envelope>
Namespace Prefixes
SOAP messages heavily use XML namespaces. Each prefix (soap:, ws:, xsi:, etc.) is bound to a URI via xmlns declarations. A good formatter preserves these declarations and keeps them aligned for readability.
Common Namespace URIs
http://schemas.xmlsoap.org/soap/envelope/— SOAP 1.1http://www.w3.org/2003/05/soap-envelope— SOAP 1.2http://www.w3.org/2001/XMLSchema-instance— XML Schema Instancehttp://www.w3.org/2001/XMLSchema— XML Schema Definition
SOAP Fault Messages
Error responses use the <soap:Fault> element within the Body:
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Invalid user ID</faultstring>
<detail>
<errorCode>USR-404</errorCode>
</detail>
</soap:Fault>
</soap:Body>
Formatting Fault messages clearly displays the error hierarchy: fault code, human-readable message, and structured detail.
Formatting Tips for SOAP
- Indent the Body content consistently so the actual business payload stands out from the envelope boilerplate.
- Keep namespace declarations on the root
Envelopeelement for clarity. - When SOAP messages contain embedded XML (e.g., Base64-encoded XML in a string element), decode and format that content separately.
Use Case
SOAP XML formatting is essential for enterprise integration developers debugging web service calls, QA engineers reviewing SOAP request/response logs, and teams maintaining legacy SOAP APIs. Formatted SOAP messages make it easy to compare request structures and identify missing or malformed fields.