Closed IskandarAlex2 closed 6 months ago
I'm making sitemap generator and need to add the urls within an array but everytime I do it gave me
Writer: emitter error: last element name is not available
#[derive(Debug, Serialize, PartialEq)] #[serde(rename = "url")] pub struct Url { pub loc: String, pub lastmod: String, pub changefreq: String, pub priority: f32, } #[derive(Debug, Serialize, PartialEq)] #[serde(rename = "urlset")] pub struct UrlSet { #[serde(rename = "url")] pub urls: Vec<Url>, }
let url1 = Url { loc: "https://example.com/page1".to_string(), lastmod: "2024-05-19".to_string(), changefreq: "weekly".to_string(), priority: 0.8, }; let url2 = Url { loc: "https://example.com/page2".to_string(), lastmod: "2024-05-18".to_string(), changefreq: "monthly".to_string(), priority: 0.6, }; let urlset = UrlSet { urls: vec![url1, url2], }; // Serialize UrlSet to XML string let xml_string = match to_string(&urlset) { Ok(s) => s, Err(err) => { println!("{}", err); return Err(Box::new(std::io::Error::new( std::io::ErrorKind::Other, "Unable to serialize UrlSet to XML", ))); } };
I gave in a just made a simple writer myself.
I'm making sitemap generator and need to add the urls within an array but everytime I do it gave me