[−][src]Crate simple_xml_serialize_macro
This is a procedural macro library to enable simple xml serialization by annotating structs with attribute macros.
extern crate simple_xml_serialize; extern crate simple_xml_serialize_macro; use simple_xml_serialize::XMLElement; use simple_xml_serialize_macro::xml_element; #[xml_element("custom_name_here")] struct MyPoint { #[sxs_type_attr(rename="lat")] latitude: f32, #[sxs_type_attr] lon: f32, #[sxs_type_attr] active: bool, #[sxs_type_empty_attr] grid_system: String, #[sxs_type_element(rename="Identifier")] name: MyName, } #[xml_element("Name")] struct MyName { #[sxs_type_text] val: String, } fn main() { let my_point = MyPoint { latitude: 43.38, lon: 60.11, active: true, grid_system: "wgs84".to_string(), name: MyName{val: "p1".to_string()}, }; let my_point_xml = XMLElement::from(my_point); // can also take refs `&my_point` let expected = r#"<custom_name_here lat="43.38" lon="60.11" active="true" wgs84><Identifier>p1</Identifier></custom_name_here>"#; assert_eq!(expected, my_point_xml.to_string()); let expected = r#"<custom_name_here lat="43.38" lon="60.11" active="true" wgs84> <Identifier> p1 </Identifier> </custom_name_here>"#; assert_eq!(expected, my_point_xml.to_string_pretty("\n"," ")); }
Attribute Macros
xml_element |