1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use serde::Serialize;

use crate::documents::*;
use crate::xml_builder::*;

#[derive(Serialize, Debug, Clone, PartialEq, Default)]
pub struct DataBinding {
    pub xpath: Option<String>,
    pub prefix_mappings: Option<String>,
    pub store_item_id: Option<String>,
}

impl DataBinding {
    pub fn new() -> Self {
        Default::default()
    }

    pub fn xpath(mut self, xpath: impl Into<String>) -> Self {
        self.xpath = Some(xpath.into());
        self
    }

    pub fn prefix_mappings(mut self, m: impl Into<String>) -> Self {
        self.prefix_mappings = Some(m.into());
        self
    }

    pub fn store_item_id(mut self, id: impl Into<String>) -> Self {
        self.store_item_id = Some(id.into());
        self
    }
}

impl BuildXML for DataBinding {
    fn build(&self) -> Vec<u8> {
        XMLBuilder::new()
            .data_binding(
                self.xpath.as_ref(),
                self.prefix_mappings.as_ref(),
                self.store_item_id.as_ref(),
            )
            .build()
    }
}

#[cfg(test)]
mod tests {

    use super::*;
    #[cfg(test)]
    use pretty_assertions::assert_eq;
    use std::str;

    #[test]
    fn test_delete_default() {
        let b = DataBinding::new().xpath("root/hello").build();
        assert_eq!(
            str::from_utf8(&b).unwrap(),
            r#"<w:dataBinding w:xpath="root/hello" />"#
        );
    }
}