forked from Florob/RustyXML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.rs
48 lines (45 loc) · 1.54 KB
/
demo.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// RustyXML
// Copyright (c) 2013 Florian Zeitz
//
// This project is MIT licensed.
// Please see the COPYING file for more information.
extern mod xml;
fn main()
{
let mut p = xml::Parser::new();
let mut e = xml::ElementBuilder::new();
let stdin = std::io::stdin();
loop {
if stdin.eof() { return; }
let input = stdin.read_line();
do p.parse_str(input + "\n") |event| {
/*
match event {
Ok(xml::PI(cont)) => print(fmt!("<?%s?>", cont)),
Ok(xml::StartTag(name, attrs)) => {
print(fmt!("<%s", name));
for attrs.iter().advance |attr| {
print(fmt!(" %s='%s'", attr.name, attr.value));
}
print(">");
}
Ok(xml::EndTag(name)) => print(fmt!("</%s>", name)),
Ok(xml::Characters(chars)) => print(chars),
Ok(xml::CDATA(chars)) => print(fmt!("<![CDATA[%s]]>", chars)),
Ok(xml::Comment(cont)) => print(fmt!("<!--%s-->", cont)),
// Ok(event) => println(fmt!("%?", event)),
Err(e) => println(fmt!("%?", e))
}
/*/
match event {
Ok(event) => match e.push_event(event) {
Ok(Some(e)) => println(fmt!("%?", e)),
Ok(None) => (),
Err(e) => println(fmt!("%?", e)),
},
Err(e) => println(fmt!("%?", e))
}
//*/
}
}
}