Skip to main content

oxml_drawing/
namespace.rs

1use oxml_core::OxmlError;
2use quick_xml::XmlVersion;
3use quick_xml::events::BytesStart;
4
5pub const A_NS: &str = "http://schemas.openxmlformats.org/drawingml/2006/main";
6pub const A_PREFIX: &str = "a";
7pub const PIC_NS: &str = "http://schemas.openxmlformats.org/drawingml/2006/picture";
8pub const PIC_PREFIX: &str = "pic";
9
10/// Rejects a local binding that would change the meaning of a fixed `a:` tag.
11///
12/// Call this only for elements that a typed parser rewrites. Opaque elements
13/// keep their producer namespace declarations and are not inspected.
14pub(crate) fn reject_conflicting_a_prefix(element: &BytesStart<'_>) -> Result<(), OxmlError> {
15    for attribute in element.attributes() {
16        let attribute = attribute.map_err(OxmlError::from)?;
17        if attribute.key.as_ref() == b"xmlns:a" {
18            let value = attribute
19                .decoded_and_normalized_value(XmlVersion::Implicit1_0, element.decoder())
20                .map_err(OxmlError::from)?;
21            if value != A_NS {
22                return Err(OxmlError::InvalidValue(
23                    "xmlns:a conflicts with the fixed DrawingML writer namespace".to_owned(),
24                ));
25            }
26        }
27    }
28    Ok(())
29}