expression
XML attribute mapping
Represent an XML attribute separately from a child element by using quick-xml’s attribute naming convention. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): 7 Pen Common mistake: Renaming an attribute to id without the attribute marker.
Formal Syntax & Structure
rust syntaxrust
#[serde(rename = "@id")]Working Example
Example Snippetrust
fn main() { #[derive(serde::Deserialize)] struct Item { #[serde(rename = "@id")] id: u32, name: String } let item: Item = quick_xml::de::from_str(r#"<item id="7"><name>Pen</name></item>"#).unwrap(); println!("{} {}", item.id, item.name);}