Skip to content

Instantly share code, notes, and snippets.

@orisano
Last active June 28, 2024 08:31
Show Gist options
  • Save orisano/4287f4784bfea2248de181d46d3d0465 to your computer and use it in GitHub Desktop.
Save orisano/4287f4784bfea2248de181d46d3d0465 to your computer and use it in GitHub Desktop.
use quick_xml::events::Event;
use quick_xml::reader::Reader;
fn main() {
let mut reader = Reader::from_file("out.xml").unwrap();
let mut buf = Vec::new();
let mut in_location = false;
let mut count = 0;
loop {
match reader.read_event_into(&mut buf) {
Err(e) => panic!("Error: {}", e),
Ok(Event::Eof) => break,
Ok(Event::Start(ref e)) => {
match e.name().as_ref() {
b"location" => in_location = true,
_ => in_location = false,
}
}
Ok(Event::Text(e)) => {
if in_location {
if e.windows(6).find(|w| w == b"Africa").is_some() {
count += 1;
}
}
}
_ => (),
}
}
buf.clear();
println!("Counter = {}", count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment