From 0490f4f3b63e9248233d6fb84b2e9f0939ffe1f9 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 23 Jan 2019 04:04:03 +0400 Subject: Wed, 23 Jan 2019 04:04:03 +0400 Signed-off-by: Valentin Popov --- Cargo.toml | 4 ++++ src/main.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a91a1bc..7934a51 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,7 @@ authors = ["Valentin Popov "] edition = "2018" [dependencies] +serde = "1.0.85" +serde_derive = "1.0.85" +serde_json = "1.0.36" +xml-rs = "0.8.0" 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; + } + _ => {} + } + } } -- cgit v1.2.3