docx-reader 0.1.1

A .docx file reader in rust
Documentation
use std::io::Read;
use std::str::FromStr;
use xml::attribute::OwnedAttribute;
use xml::reader::{EventReader, XmlEvent};

use super::*;

impl ElementReader for Paragraph {
	fn read<R: Read>(
		r: &mut EventReader<R>,
		attrs: &[OwnedAttribute],
	) -> Result<Self, ReaderError> {
		let mut p = Paragraph::new();
		if let Some(para_id) = read(attrs, "paraId") {
			p = p.id(para_id);
		}
		loop {
			let e = r.next();
			match e {
				Ok(XmlEvent::StartElement {
					attributes, name, ..
				}) => {
					let e = XMLElement::from_str(&name.local_name).unwrap();

					match e {
						XMLElement::Run => {
							let run = Run::read(r, &attributes)?;
							p = p.add_run(run);
							continue;
						}
						XMLElement::Hyperlink => {
							let link = Hyperlink::read(r, &attributes)?;
							p = p.add_hyperlink(link);
							continue;
						}
						XMLElement::Insert => {
							let ins = Insert::read(r, &attributes)?;
							p = p.add_insert(ins);
							continue;
						}
						XMLElement::Delete => {
							let del = Delete::read(r, &attributes)?;
							p = p.add_delete(del);
							continue;
						}
						XMLElement::ParagraphProperty => {
							if let Ok(pr) = ParagraphProperty::read(r, &attributes) {
								p.has_numbering = pr.numbering_property.is_some();
								p.property = pr;
							}
							continue;
						}
						_ => {}
					}
				}
				Ok(XmlEvent::EndElement { name, .. }) => {
					let e = XMLElement::from_str(&name.local_name).unwrap();
					if e == XMLElement::Paragraph {
						return Ok(p);
					}
				}
				Err(_) => return Err(ReaderError::XMLReadError),
				_ => {}
			}
		}
	}
}