Macro mws::write_xml
[−]
[src]
macro_rules! write_xml { ($w:expr, ) => { ... }; ($w:expr, [ $b:block ] $($rest:tt)*) => { ... }; ($w:expr, $e:tt) => { ... }; ($w:expr, $tag_name:ident[$($attr_name:ident=$attr_value:expr),*][ $($inner:tt)* ] $($rest:tt)* ) => { ... }; }
Writes to XmlEventWriter
Example
use xml::{EventWriter, EmitterConfig}; let mut writer = EventWriter::new_with_config(vec![], EmitterConfig::new().perform_indent(true)); let context = vec!["context-value-0", "context-value-1"]; { let w = &mut writer; write_xml!(w, Enevolop[Static="static-value", FromContext=context[0] ][ Header[FirstAttr="1", SecondAttr="2" ][] Body[][ "Body Content" ] [{ write_xml!(w, ContextItems[][ [{ for (i, v) in context.iter().enumerate() { let idx = i.to_string(); write_xml!(w, Item[Index=(&idx)] [ (*v) ] ).unwrap(); } Ok(()) }] ] ) }] Footer[][ (context[1]) ] ] ).unwrap(); } let xml = String::from_utf8(writer.into_inner()).unwrap(); assert_eq!( xml, r#"<?xml version="1.0" encoding="utf-8"?> <Enevolop Static="static-value" FromContext="context-value-0"> <Header FirstAttr="1" SecondAttr="2" /> <Body>Body Content</Body> <ContextItems> <Item Index="0">context-value-0</Item> <Item Index="1">context-value-1</Item> </ContextItems> <Footer>context-value-1</Footer> </Enevolop>"# );