aboutsummaryrefslogtreecommitdiff
path: root/src/parser.rs
blob: ccc082aa0d51eaa7546e0716c7a405b7a66a2135 (plain) (blame)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::fs::File;
use std::io::BufReader;

extern crate xml;
use xml::reader::{EventReader, XmlEvent};

#[derive(RustcEncodable)]
pub struct ParserResult {
	pub external_id: String,
	pub meeting_id: String,
	pub meeting_name: String,
}

pub fn parse(content: BufReader<File>) -> 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;
}