1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
use XmlElement; use xml::reader::{XmlEvent}; #[derive(Debug)] pub struct XmlElementBuilder { _parent : XmlEvent, _children: Vec<XmlElement>, _data : Option<XmlEvent> } impl XmlElementBuilder { pub fn new(event: XmlEvent) -> XmlElementBuilder { XmlElementBuilder{_parent: event, _children: Vec::new(), _data: None} } pub fn add_child(&mut self, builder: XmlElementBuilder) -> () { self._children.push(builder.build()); } pub fn add_data(&mut self, data : XmlEvent) -> () { self._data = Some(data) } pub fn build(self) -> XmlElement { XmlElement::custom(self._parent, self._children, self._data) } }