XML Input

Rust Output

What the generator writes

Paste an XML sample and you get one pub struct per element name with serde derives. 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.

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, then call 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.

1

Paste a sample with repeats and optional fields

Paste XML into XML Input or Upload a file. Repeated elements need to appear at least twice to become a Vec. 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.

2

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.

3

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 <p>Hi <b>Ava</b></p>?

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. It is parsed in your browser. Inputs over 256 KB are rejected; trim the file to a few representative records.

Related tools

Other converters and checks that pair well with this one: