XML to Rust Struct Generator
serde structs that deserialize with quick-xml
XML Input
Rust Output
Paste your XML on the left and the Rust code shows up here.
Or drop a file on this box, , or .
What the generator writes
The generator reads your XML and writes a pub struct for every distinct element, deriving Debug, Default and the serde traits. Every field carries an explicit #[serde(rename = "...")] that follows quick-xml's serde conventions: "@id" for an attribute, "$text" for an element's own text, and the plain element name for children, so poolSize maps onto pool_size without guesswork.
Repeated elements become Vec<T> with #[serde(default)], so an empty list is fine. Fields that are missing from some records become Option<T>, and a type that contains itself gets Option<Box<T>>. Numbers are typed i32, i64 or f64 from the values you paste. Field names are snake_case; Rust keywords like type get a trailing underscore, and the rename keeps the original XML name.
We compiled the output and deserialized the page's own sample with quick-xml 0.42 and serde 1.0. Add serde = { version = "1", features = ["derive"] } and quick-xml = { version = "0.42", features = ["serialize"] } to Cargo.toml and deserialize with quick_xml::de::from_str::<Config>(&xml). Generation happens in your browser; nothing is uploaded.
How to use it
Paste a sample, pick two options, copy the module.
Paste a sample with repeats and optional fields
Drop XML into XML Input or load a file with Upload. The sample has two <feature> elements, which is why feature comes out as Vec<Feature> with #[serde(default)]; one copy would give a single struct field. Sample loads a service config:
<config version="3">
<server><host>0.0.0.0</host><port>8080</port></server>
<feature name="beta-search">true</feature>
<feature name="bulk-export">false</feature>
</config> The XML Validator pinpoints syntax errors if the output panel reports one.
Set the options
Root struct renames the top-level struct (empty uses the root element name). Option<T> for missing fields wraps optional fields; untick it to get plain fields with #[serde(default)]. Derive Serialize adds Serialize for writing XML back with quick_xml::se::to_string.
Copy or download
Download saves a .rs file you can add as a module; Copy puts it on the clipboard.
Where it helps
Config files
Services that inherited an XML config can load it into typed structs at startup instead of walking events by hand.
Feeds and partner APIs
Sitemaps, RSS, invoices and other XML feeds deserialize straight into structs, with Vec fields for the repeated entries.
CLI tools
A small command-line tool that converts or validates XML files gets its data model in a minute.
Moving off a hand-written parser
Replace a quick-xml event loop with serde structs and keep the field-by-field mapping in one readable place.
Common questions
Which crates does the code need?
serde with the derive feature and quick-xml with the serialize feature. The attribute names (@ and $text) are quick-xml's convention; serde-xml-rs uses different ones.
Why does every field have a rename?
XML names are usually camelCase or kebab-case while Rust fields are snake_case. An explicit serde rename on every field keeps the mapping obvious and survives refactors.
What happens with mixed content like
Hi Ava
?The child elements are mapped, but the text in between is left out with a comment: quick-xml rejects a struct whose $text field would be filled from several text pieces. Use $value with an enum if you really need mixed content.
How are namespaces handled?
quick-xml matches on the local name and ignores the prefix, so the renames use local names (meta for <x:meta>). If two elements share a local name in different namespaces, rename one of them by hand.
How are numeric types picked?
From your sample: whole numbers become i32 or i64, decimals f64, true/false bool. A value with a leading zero, or one too large for i64, stays a String.
Is my XML uploaded?
No. DOMParser reads it in this tab and the Rust source is assembled right there, so the config never goes over the network. Anything above 256 KB is rejected, but a config with one example of each section is all the struct inference uses.
Related tools
Config files are rarely clean on the first paste. Format or validate the XML first, and when the same settings exist as JSON, JSON to Rust covers that version of them: