expression
XML text content mapping
Use the text mapping for a simple element body with an attribute. Mixed content containing child tags needs a separate model. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): fa سلام Common mistake: Treating arbitrary mixed markup as a single plain-text field.
Formal Syntax & Structure
rust syntaxrust
#[serde(rename = "$text")]Working Example
Example Snippetrust
fn main() { #[derive(serde::Deserialize)] struct Label { #[serde(rename = "@lang")] lang: String, #[serde(rename = "$text")] body: String } let label: Label = quick_xml::de::from_str(r#"<label lang="fa">سلام</label>"#).unwrap(); println!("{} {}", label.lang, label.body);}