Julio Biason
6 years ago
commit
133d4f6792
4 changed files with 62 additions and 0 deletions
@ -0,0 +1,14 @@
|
||||
[[package]] |
||||
name = "RustyXML" |
||||
version = "0.1.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
|
||||
[[package]] |
||||
name = "enexparser" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"RustyXML 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", |
||||
] |
||||
|
||||
[metadata] |
||||
"checksum RustyXML 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9222d58bccd9e6e3b82098a2ec142ad34e5d433de986d46cec03ad3a2b5fd529" |
@ -0,0 +1,8 @@
|
||||
[package] |
||||
name = "enexparser" |
||||
version = "0.1.0" |
||||
authors = ["Julio Biason <julio.biason@deliverit.com.br>"] |
||||
edition = "2018" |
||||
|
||||
[dependencies] |
||||
RustyXML = "0.1.1" |
@ -0,0 +1,36 @@
|
||||
use std::env; |
||||
use xml::{Event, Parser}; |
||||
use std::fs::File; |
||||
use std::io::prelude::*; |
||||
|
||||
fn main() { |
||||
let args:Vec<_> = env::args().collect(); |
||||
if args.len() != 2 { |
||||
println!("Required: filename."); |
||||
std::process::exit(2); |
||||
} |
||||
|
||||
let filename = &args[1]; |
||||
|
||||
println!("Will process {}", filename); |
||||
|
||||
// Need to find a way to load small chunks and feed it to the parser while parsing.
|
||||
// (E.g., load 1024 bytes, feed it to the parser and, if the parser can't continue,
|
||||
// feed more data, till the end of file).
|
||||
let mut file = File::open(filename).unwrap(); |
||||
let mut contents = String::new(); |
||||
file.read_to_string(&mut contents).unwrap(); |
||||
|
||||
let mut parser = Parser::new(); |
||||
parser.feed_str(&contents); |
||||
|
||||
for event in parser { |
||||
match event.unwrap() { |
||||
Event::ElementStart(tag) => println!("Start: {}", tag.name), |
||||
Event::ElementEnd(tag) => println!("End: {}", tag.name), |
||||
Event::Characters(data) => println!("Data: {}", data), |
||||
Event::CDATA(data) => println!("CDATA: {}", data), |
||||
_ => () |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue