Swift to XML Converter
Paste Swift structs or a populated instance. Get clean XML back.
Input
Output
Paste your Swift code on the left and press Convert.
Or drop a file on this box, , or .
What this tool does
Swift gives you JSONEncoder and PropertyListEncoder in Foundation but nothing that writes arbitrary XML, so when an iOS app still has to talk to a SOAP-based ERP or you need a fixture for an XMLParser delegate test, someone ends up typing the document by hand. Paste your structs and a populated let order = Order(...), then click Convert; what comes back from our backend is an XML document whose root is the struct name and whose children follow the stored properties.
The output follows Codable conventions where they apply. A CodingKeys enum renames tags, which is why the sample's orderId comes out as <OrderId>. Decimal(string: "249.99")! is written as 249.99, Date as ISO-8601 text, and UUID in its usual 8-4-4-4-12 form. An optional that is nil keeps its place as an empty element. A [OrderItem] property gets a wrapper named after the property, holding an <OrderItem> element for each value.
Coding customisations are honoured too. A nested enum CodingKeys: String, CodingKey remaps property names in the output, so orderId can surface as OrderId in the XML without you touching the struct. Nested structs and enums are expanded inline. If you paste several types, each one lands in the output with its shape intact: the converter follows the same broad design goals as the Swift API Design Guidelines, so names and casing stay predictable.
How to use it
Paste, Convert, copy. Below is what each step means for a Swift file.
Paste your Swift (or try the sample)
Paste the Swift into the left editor as it is in Xcode. Load Sample loads three Codable structs, a CodingKeys enum that renames one property, and an Order built with Decimal(string:) prices, two line items and a London address.
import Foundation, extensions, protocol conformances and @propertyWrapper declarations can stay in the paste (the Swift docs cover the syntax if you need a refresher). What matters for the output is the stored properties and the values in the initializer call.
Hit Convert
Press the green Convert button and the Swift is handed to our backend, which applies your CodingKeys, reads the memberwise initializer call and sends back XML. Nothing is compiled, and the editors stay dimmed under "Converting..." until the reply lands.
Copy the XML
Read the XML in the right pane. Feed it to XMLParser(data:) in an XCTest to check that your delegate picks up every element, or copy it into the request body your SOAP client should send. It also parses cleanly in lxml or System.Xml if the consumer is not Apple code.
When this actually comes in handy
iOS / macOS plist generation
Take a Swift settings struct and get an Info.plist-style XML document you can drop straight into Xcode, no hand-typed <key></key> pairs, no whitespace bugs. Pairs well with Apple's PropertyListSerialization APIs on the decoding side.
SOAP clients on Apple platforms
A Swift request type needs to leave the app as SOAP. Paste the struct, drop the XML body into SoapUI or Postman, verify the contract without writing the envelope by hand.
Seeding test fixtures
The Order you construct in a unit test can become the XML seed file for an XCTest integration test or a mock server, so the fixture starts out matching the model.
Keeping docs in sync
Generate XML examples for a README, an internal wiki, or XSD-backed schema docs directly from your actual Swift models, so the documentation never drifts out of step with the code.
Common questions
Can I paste multiple structs at once?
Yes. The backend takes pastes of up to 64 KB. If the paste includes an instance, that value is serialized and the other structs appear where it refers to them. With only type declarations, the converter writes a template where strings are empty, numbers are 0 and booleans false, and several unrelated top-level types are gathered under one <Root> element.
Does it honour CodingKeys?
Yes. A nested enum CodingKeys: String, CodingKey remaps property names in the XML output: case orderId = "OrderId" will emit <OrderId> instead of <orderId>. Properties not listed in CodingKeys fall back to their Swift name. This matches how Codable works in practice.
How does it handle Decimal, Date, and Optional?
Decimal and Double are written as plain numbers, so Decimal(string: "150.01")! becomes 150.01 with the force-unwrap gone. Date values are formatted as ISO-8601, the way ISO8601DateFormatter would print them, and UUID keeps its hyphenated form. A nil optional is written as an empty element, which matters if an XSD on the other side marks that element as required.
What about enums with associated values and arrays?
An enum with a raw value, such as enum Status: String { case shipped }, contributes just its raw value as text. An enum with associated values is written as an element named after the case, with the associated values nested inside it. Arrays get a wrapper named after the property and an element per value, and a [String: Int] dictionary becomes <Entry> elements with a key and a value each.
Is my code stored?
The Swift source reaches our backend only when you click Convert, for that conversion alone, and the site does not save it. API keys in a Config.swift or real user data in preview fixtures are worth replacing before you paste.
What if the Swift has property wrappers, protocols, or computed properties?
A property marked with a wrapper such as @Published is written with its underlying value. Protocols only describe requirements, so they add nothing, while the structs that conform to them do. Computed properties (var total: Decimal { ... }) are left out because they hold no stored state. If Xcode shows red errors on the snippet, fix those before converting; small slips are tolerated, a half-pasted file is not.
Other tools you may need
With the struct in XML form, you might want to go the other way, produce JSON from the same model, or validate the result: