Rust to XML Converter
Paste Rust structs or a struct literal. Get clean XML back.
Input
Output
Paste your Rust code on the left and press Convert.
Or drop a file on this box, , or .
What this tool does
In Rust you rarely write XML by hand until you have to: a test needs the exact document your #[derive(Serialize)] struct should produce, a legacy service wants a sample request, or you are deciding between two XML crates and want to see the target shape first. Compiling a throwaway binary just to print one struct is a lot of ceremony. Paste the struct definitions and a let order = Order { ... }; literal, and Convert gets you an XML document back from our backend, with the struct name as the root and every field as a child carrying the literal's value.
The converter respects the serde attributes it finds, close to how serde-xml-rs or quick-xml treat them. #[serde(rename = "OrderId")] changes the tag, #[serde(skip)] removes the field, and quick-xml's "@id" rename turns a field into an attribute. String::from("ORD-4821") is reduced to its text, an f64 to a plain number, and Some(x) unwraps to x. Each Vec field is wrapped in an element carrying the field name, and every value in the vector is written inside it under the element type's name.
Serde attributes are honoured. #[serde(rename = "x")] on a field renames the element in the output, #[serde(rename = "x")] on the struct renames the wrapping root, #[serde(skip)] drops the field, and #[serde(flatten)] pulls a nested struct up a level. Enums are emitted with the standard serde tagging rules: externally tagged by default, adjacently or internally tagged if you set #[serde(tag = "...")]. If you want the deep version, The Rust Book is a solid jumping-off point for the ownership and type-system pieces underneath.
How to use it
Load Sample, Convert, copy. Each step below is described for Rust input specifically.
Paste your Rust (or try the sample)
Paste your Rust into the left editor, use statements and derives included. Load Sample fills in an Order struct that shows off two serde attributes (a rename to OrderId and a skip_serializing_if on an Option), plus a struct literal with a two-item vec! and a nested Address.
You do not need to strip use statements, remove derive macros, or clean up lifetime annotations. Leave the code the way rustfmt left it. Just paste.
Hit Convert
Hit the green Convert button. We send the source to our backend, which reads the struct definitions and the literal, resolves the serde attributes and returns the XML. Nothing is compiled or run, and a "Converting..." overlay covers the panes until the reply arrives.
Copy the XML
The document appears in the right pane with an XML declaration and two-space indentation. Drop it into a tests/fixtures/order.xml file and assert against it with quick_xml::de::from_str, or use it as the expected body when you mock a SOAP endpoint.
When this actually comes in handy
Systems-level SOAP integration
Rust services often sit next to legacy systems that still speak SOAP. Paste your request struct, grab the XML body, test it in SoapUI before wiring the HTTP client: faster than writing the envelope by hand. Pair with a crate from crates.io like reqwest for the transport.
Config files for services and daemons
A settings struct with 30+ fields becomes a ready-to-edit XML template. No handwritten boilerplate, no missed fields when the struct grows.
Seeding test fixtures
A struct literal you already wrote for a unit test becomes the seed file for an integration test or a wiremock stub, so the XML fixture and the Rust type start out matching.
Keeping docs in sync
Generate XML examples for a README, crate docs, or XSD-backed schema documentation directly from your actual structs, so docs match the code instead of drifting.
Common questions
Can I paste multiple structs at once?
Yes. Paste a whole module. Each top-level struct or enum comes through with nested types expanded and default values filled in. Nothing is dropped silently.
Does it honour #[serde(rename)] and #[serde(skip)]?
Yes. #[serde(rename = "x")] on a field renames the XML element, #[serde(rename = "x")] on the struct renames the wrapping root, #[serde(skip)] drops the field entirely, and #[serde(flatten)] pulls a nested struct up a level. #[serde(rename_all = "PascalCase")] is applied to every field in the struct. That matches what serde actually does at runtime.
How does it handle Option<T> and skip_serializing_if?
A None value becomes an empty element by default, so the shape stays consistent and XSDs keep validating. If the field has #[serde(skip_serializing_if = "Option::is_none")], None values are dropped entirely. Some(x) is always serialised as x itself.
What about enums, Vec, and HashMap?
A plain enum is wrapped in an element named after the variant, so Status::Shipped shows up as <Shipped>, and a variant with fields nests those fields inside it; mark the enum #[serde(untagged)] and the wrapper is dropped. A Vec<T>, a slice or a fixed array [T; N] gets a parent element named after the field with an element per value, tagged with the element type. HashMap and BTreeMap with string keys are written as <Entry><Key/><Value/></Entry> pairs.
Is my code stored?
When you press Convert, the Rust source is posted to our conversion backend and the XML returns in the response; the site does not save it. Config structs often get pasted together with a Default impl holding real connection strings or tokens, so replace those first.
What if the Rust has lifetimes, traits, or unsafe blocks?
Lifetimes like &'a str only matter to the borrow checker, so the converter reads the field as text and ignores the annotation. Traits and impl blocks hold behaviour, not data, and are skipped; the structs that carry values are what get written. unsafe blocks, macros other than vec! and computed values cannot be evaluated, so give the field a literal if you want a real value in the output. If cargo check fails on the snippet, fix that first; the converter copes with small gaps, not with half a file.
Other tools you may need
From a Rust struct to XML is one direction. These cover the reverse trip, the JSON equivalent, and checking what you got: