Hi,
I'm parsing XML data (crate roxmltree) and store the values in a BTreeMap (order of insertion is important). That code is working fine, but not for XML that have multiple occurrence of e.g the tag . I was looking for a way (if possible) to insert UUID1 and the value for the first occurrence of the tag , UUID2 and the value for the next occurrence in the BTreeMap.
Attempts so far all fail because of not getting beyond the borrow checker and the iteration of the values which is outside of the first for loop and the match pattern.
Any ideas on how to solve this would be very much appreciated. Attempts such as the snippet below do not work
let t_uuid = tag_uuid.to_owned();
variable = format!("{}{}", t_uuid, x); (x :u32 )
junctionmap.insert(variable, val);
use roxmltree::*;
use std::collections::BTreeMap;
pub fn btree_xml_data(root_elem: &Document) {
let mut junctionmap: BTreeMap<&str, &str> = BTreeMap::new();
for desc in root_elem.descendants() {
match desc.tag_name().name() {
"VERSION" => {
let tag_version = &desc.tag_name().name();
let val = &desc.text().unwrap_or("");
junctionmap.insert(tag_version, val);
}
"NAME" => {
let tag_jctname = &desc.tag_name().name();
let val = &desc.text().unwrap_or("");
junctionmap.insert(tag_jctname, val);
}
"UUID" => {
let tag_uuid = &desc.tag_name().name();
let val = &desc.text().unwrap_or("");
junctionmap.insert(tag_uuid, val);
}
_ => (),
}
}
for (tag, tagvalue) in &junctionmap {
println!("{}: \"{}\"", tag, tagvalue);
}
}