Skip to main content

xlsbye_xml/
content_types.rs

1use crate::writer::{Result, XmlWriter};
2use std::io::Write;
3use xlsbye_core::xml_names::CONTENT_TYPES_NS;
4
5pub fn write_content_types(
6    writer: impl Write,
7    defaults: &[(String, String)],
8    overrides: &[(String, String)],
9) -> Result<()> {
10    let mut writer = XmlWriter::new(writer);
11    writer.write_xml_declaration()?;
12    writer.write_start_element_with_ns(
13        "Types",
14        [("", CONTENT_TYPES_NS)],
15        std::iter::empty::<(&str, &str)>(),
16    )?;
17
18    for (extension, content_type) in defaults {
19        writer.write_empty_element(
20            "Default",
21            [
22                ("Extension".to_string(), extension.clone()),
23                ("ContentType".to_string(), content_type.clone()),
24            ],
25        )?;
26    }
27
28    for (part_name, content_type) in overrides {
29        writer.write_empty_element(
30            "Override",
31            [
32                ("PartName".to_string(), part_name.clone()),
33                ("ContentType".to_string(), content_type.clone()),
34            ],
35        )?;
36    }
37
38    writer.write_end_element("Types")?;
39    Ok(())
40}