oox 0.1.0

Open Office XML file format deserializer
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use crate::{error::MissingAttributeError, xml::XmlNode};

pub(crate) trait XmlNodeExt {
    // It's a common pattern throughout the OpenOffice XML file format that a simple type is wrapped in a complex type
    // with a single attribute called `val`. This is a small wrapper function to reduce the boiler plate for such
    // complex types
    fn get_val_attribute(&self) -> std::result::Result<&String, MissingAttributeError>;
}

impl XmlNodeExt for XmlNode {
    fn get_val_attribute(&self) -> std::result::Result<&String, MissingAttributeError> {
        self.attributes
            .get("w:val")
            .ok_or_else(|| MissingAttributeError::new(self.name.clone(), "val"))
    }
}