aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2019-01-26 18:08:55 +0300
committerValentin Popov <info@valentineus.link>2019-01-26 18:08:55 +0300
commit4edb511fe6bfe020e70d6ade1776dd8099a10ed0 (patch)
tree922b764724650b73d3638b56a92d0b4d90540a13 /src/main.rs
parent0490f4f3b63e9248233d6fb84b2e9f0939ffe1f9 (diff)
downloadbbb2json-4edb511fe6bfe020e70d6ade1776dd8099a10ed0.tar.xz
bbb2json-4edb511fe6bfe020e70d6ade1776dd8099a10ed0.zip
Sat, 26 Jan 2019 19:08:55 +0400
Signed-off-by: Valentin Popov <info@valentineus.link>
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/main.rs b/src/main.rs
index 1f0c9f1..881237d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,7 +11,7 @@ use serde::Serialize;
use serde_json::Result;
use xml::reader::{EventReader, XmlEvent};
-#[derive(Serialize)]
+#[derive(Serialize, Clone)]
struct Record {
externalId: String,
meetingId: String,
@@ -24,32 +24,40 @@ fn main() {
let parser = EventReader::new(file);
- for e in parser {
- match e {
+ let mut data = Record {
+ externalId: "".to_string(),
+ meetingId: "".to_string(),
+ meetingName: "".to_string(),
+ };
+
+ for element in parser {
+ match element {
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);
+ for attribute in attributes {
+ let name: String = attribute.name.local_name.to_string();
+ let value: String = attribute.value.to_string();
+
+ if name == "externalId" {
+ data.externalId = value;
+ } else if name == "meetingId" {
+ data.meetingId = value;
+ } else if name == "meetingName" {
+ data.meetingName = value;
+ }
}
}
- Err(e) => {
- dbg!(e);
+ Err(error) => {
+ dbg!(error);
break;
}
_ => {}
}
}
+
+ let j = serde_json::to_string(&data);
+ dbg!(j);
}