()
| 1 | use xmltree::{Element, XMLNode}; |
| 2 | |
| 3 | fn main() -> Result<(), Box<dyn std::error::Error + 'static>> { |
| 4 | println!("Hello, world!"); |
| 5 | let data = std::fs::read_to_string("../../cd-list.xml")?; |
| 6 | let mut root = Element::parse(data.as_bytes()).unwrap(); |
| 7 | for child in &root.children { |
| 8 | println!("child {:?}", child); |
| 9 | } |
| 10 | let titles = &root.get_child("title").unwrap(); |
| 11 | for title in &titles.children { |
| 12 | println!("title {:?}", title.as_text()); |
| 13 | println!("title {:?}", &titles.get_text()); |
| 14 | } |
| 15 | let cd = &root.get_child("cd").unwrap(); |
| 16 | let track_list = cd.get_child("track-list").unwrap(); |
| 17 | let track = track_list.get_child("track").unwrap(); |
| 18 | println!("track-no {:?}", track.attributes["no"]); |
| 19 | |
| 20 | let mut newcd = Element::new("cd"); |
| 21 | let mut artist = Element::new("artist"); |
| 22 | artist.children.push(XMLNode::Text("Bob".to_owned())); |
| 23 | artist |
| 24 | .attributes |
| 25 | .insert("country".to_owned(), "DE".to_owned()); |
| 26 | let mut title = Element::new("title"); |
| 27 | title |
| 28 | .children |
| 29 | .push(XMLNode::Text("Song for Alice".to_owned())); |
| 30 | newcd.children.push(XMLNode::Element(title)); |
| 31 | root.children.push(XMLNode::Element(newcd)); |
| 32 | let mut buf = Vec::<u8>::new(); |
| 33 | root.write(&mut buf).unwrap(); |
| 34 | println!("{}", String::from_utf8(buf).unwrap()); |
| 35 | Ok(()) |
| 36 | } |
nothing calls this directly
no outgoing calls
no test coverage detected