From 381a0a03a8ad45bcac875d965fa6fcaa66c831ef Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sat, 26 Jan 2019 19:37:12 +0400 Subject: Sat, 26 Jan 2019 19:37:12 +0400 Signed-off-by: Valentin Popov --- src/parser.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/parser.rs diff --git a/src/parser.rs b/src/parser.rs new file mode 100644 index 0000000..1a8249b --- /dev/null +++ b/src/parser.rs @@ -0,0 +1,51 @@ +extern crate xml; + +use std::fs::File; +use std::io::BufReader; +use xml::reader::{EventReader, XmlEvent}; + +pub struct ParserResult { + pub external_id: String, + pub meeting_id: String, + pub meeting_name: String, +} + +pub fn qwerty(content: BufReader) -> ParserResult { + let parser = EventReader::new(content); + + let mut data = ParserResult { + external_id: "".to_string(), + meeting_id: "".to_string(), + meeting_name: "".to_string(), + }; + + for element in parser { + match element { + Ok(XmlEvent::StartElement { + name: _, + attributes, + .. + }) => { + for attribute in attributes { + let name: String = attribute.name.local_name.to_string(); + let value: String = attribute.value.to_string(); + + if name == "externalId" { + data.external_id = value; + } else if name == "meetingId" { + data.meeting_id = value; + } else if name == "meetingName" { + data.meeting_name = value; + } + } + } + Err(error) => { + dbg!(error); + break; + } + _ => {} + } + } + + return data; +} -- cgit v1.2.3