docx_reader/reader/
header.rsuse std::io::Read;
use std::str::FromStr;
use xml::reader::{EventReader, XmlEvent};
use crate::reader::*;
use super::{Paragraph, Table};
impl FromXML for Header {
fn from_xml<R: Read>(reader: R) -> Result<Self, ReaderError> {
let mut parser = EventReader::new(reader);
let mut header = Self::default();
loop {
let e = parser.next();
match e {
Ok(XmlEvent::StartElement {
attributes, name, ..
}) => {
let e = XMLElement::from_str(&name.local_name).unwrap();
match e {
XMLElement::Paragraph => {
let p = Paragraph::read(&mut parser, &attributes)?;
header = header.add_paragraph(p);
continue;
}
XMLElement::Table => {
let t = Table::read(&mut parser, &attributes)?;
header = header.add_table(t);
continue;
}
_ => {}
}
}
Ok(XmlEvent::EndDocument) => break,
Err(_) => return Err(ReaderError::XMLReadError),
_ => {}
}
}
Ok(header)
}
}