aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2019-01-23 03:04:03 +0300
committerValentin Popov <info@valentineus.link>2019-01-23 03:04:03 +0300
commit0490f4f3b63e9248233d6fb84b2e9f0939ffe1f9 (patch)
treec018b492c42204b25387c0ff0dfc3f727b8e7f59 /src
parent90a91dfcf4c65276b40a137bf0d31dc83ef5f45e (diff)
downloadbbb2json-0490f4f3b63e9248233d6fb84b2e9f0939ffe1f9.tar.xz
bbb2json-0490f4f3b63e9248233d6fb84b2e9f0939ffe1f9.zip
Wed, 23 Jan 2019 04:04:03 +0400
Signed-off-by: Valentin Popov <info@valentineus.link>
Diffstat (limited to 'src')
-rw-r--r--src/main.rs54
1 files changed, 53 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index a30eb95..1f0c9f1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,55 @@
+#[macro_use]
+extern crate serde_derive;
+extern crate serde;
+extern crate serde_json;
+extern crate xml;
+
+use std::fs::File;
+use std::io::BufReader;
+
+use serde::Serialize;
+use serde_json::Result;
+use xml::reader::{EventReader, XmlEvent};
+
+#[derive(Serialize)]
+struct Record {
+ externalId: String,
+ meetingId: String,
+ meetingName: String,
+}
+
fn main() {
- println!("Hello, world!");
+ let file = File::open("events.xml").unwrap();
+ let file = BufReader::new(file);
+
+ let parser = EventReader::new(file);
+
+ for e in parser {
+ match e {
+ Ok(XmlEvent::StartElement {
+ name: _,
+ attributes,
+ ..
+ }) => {
+ for a in attributes {
+ let mut data: Record;
+
+ match a.name.local_name.as_ref() {
+ "externalId" => data.externalId = a.value.to_owned(),
+ "meetingId" => data.meetingId = a.value.to_owned(),
+ "meetingName" => data.meetingName = a.value.to_owned(),
+ _ => {}
+ };
+
+ let j = serde_json::to_string(&data);
+ dbg!(j);
+ }
+ }
+ Err(e) => {
+ dbg!(e);
+ break;
+ }
+ _ => {}
+ }
+ }
}