Open rapodaca opened 4 years ago
Using a slight modification of the code from the README and version 0.4.0:
#[macro_use] extern crate serde; extern crate serde_xml_rs; use serde_xml_rs::from_reader; #[derive(Debug, Deserialize)] struct Item { pub name: String, pub source: String } #[derive(Debug, Deserialize)] struct Project { pub name: String, #[serde(rename = "Item", default)] pub items: Vec<Item> } fn main() { let s = r##" <P name="my_project"> <Item name="hello" source="world.rs" /> </P> "##; let project: Project = from_reader(s.as_bytes()).unwrap(); println!("{:#?}", project); }
Output is:
Project { name: "my_project", items: [ Item { name: "hello", source: "world.rs", }, ], }
I expect to see an error. I can change the P tag to anything and it still works.
P
If this is expected behavior, how can I enforce the tag Project at the root?
Project
@rapodaca, thank you for submitting this.
I don't think that this is expected behavior. Rather, it is a little quirk that I knew about but didn't mind.
I'll take a stab at fixing this.
Using a slight modification of the code from the README and version 0.4.0:
Output is:
I expect to see an error. I can change the
P
tag to anything and it still works.If this is expected behavior, how can I enforce the tag
Project
at the root?