docx_reader/reader/
rels.rsuse std::io::Read;
use xml::reader::{EventReader, XmlEvent};
use crate::reader::{FromXML, ReaderError};
use super::*;
impl FromXML for Rels {
fn from_xml<R: Read>(reader: R) -> Result<Self, ReaderError> {
let parser = EventReader::new(reader);
let mut s = Self::default();
let mut depth = 0;
for e in parser {
match e {
Ok(XmlEvent::StartElement { attributes, .. }) => {
if depth == 1 {
let mut rel_type = "".to_owned();
let mut target = "".to_owned();
for attr in attributes {
let name: &str = &attr.name.local_name;
if name == "Type" {
rel_type = attr.value.clone();
} else if name == "Target" {
target = attr.value.clone();
}
}
s = s.add_rel(rel_type, target);
}
depth += 1;
}
Ok(XmlEvent::EndElement { .. }) => {
depth -= 1;
}
Err(_) => return Err(ReaderError::XMLReadError),
_ => {}
}
}
Ok(s)
}
}