use quick_xml::reader::Reader; use serde::Serialize; use xml_schema_generator::{into_struct, Options}; const XML: &str = "\ To Kill a Mockingbird Harper Lee Drama 1960 One Hundred Years of Solitude Gabriel Garcia Marquez 1984 George Orwell Dystopian Fiction 1949 "; #[derive(Debug, Clone, Serialize)] pub struct Library { #[serde(rename = "@name")] pub name: String, #[serde(rename = "$text")] pub text: Option, pub book: Vec, } #[derive(Debug, Clone, Serialize)] pub struct Book { pub title: String, pub author: String, pub publication_year: Option, pub genre: Option, #[serde(rename = "$text")] pub text: Option, } fn main() { // create struct from XML let mut reader = Reader::from_str(XML); if let Ok(root) = into_struct(&mut reader) { let struct_as_string = root.to_serde_struct(&Options::quick_xml_de().derive("Debug, Clone, Serialize")); println!("{}", struct_as_string); // this prints the struct Library and Book as listed above, using a different derive attribute } }