docx_rs/reader/
text_box_content.rs1use std::io::Read;
2use std::str::FromStr;
3
4use super::*;
5
6impl ElementReader for TextBoxContent {
7 fn read<R: Read>(
8 r: &mut EventReader<R>,
9 _attrs: &[OwnedAttribute],
10 ) -> Result<Self, ReaderError> {
11 let mut content = TextBoxContent::new();
12 loop {
13 let e = r.next();
14 match e {
15 Ok(XmlEvent::StartElement {
16 name, attributes, ..
17 }) => {
18 let e = XMLElement::from_str(&name.local_name)
19 .expect("should convert to XMLElement");
20 match e {
21 XMLElement::Paragraph => {
22 let p = Paragraph::read(r, &attributes)?;
23 content = content.add_paragraph(p);
24 continue;
25 }
26 XMLElement::Table => {
27 let t = Table::read(r, &attributes)?;
28 content = content.add_table(t);
29 continue;
30 }
31 _ => {}
32 }
33 }
34 Ok(XmlEvent::EndElement { name, .. }) => {
35 let e = XMLElement::from_str(&name.local_name).unwrap();
36 if e == XMLElement::TxbxContent {
37 return Ok(content);
38 }
39 }
40 Err(_) => return Err(ReaderError::XMLReadError),
41 _ => {}
42 }
43 }
44 }
45}