Skip to main content

sheetkit_xml/
namespaces.rs

1//! OOXML namespace definitions.
2//! Standard namespaces used across all XML documents.
3
4// Core spreadsheet namespace
5pub const SPREADSHEET_ML: &str = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
6
7// Relationship namespaces
8pub const RELATIONSHIPS: &str =
9    "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
10pub const PACKAGE_RELATIONSHIPS: &str =
11    "http://schemas.openxmlformats.org/package/2006/relationships";
12
13// Content Types
14pub const CONTENT_TYPES: &str = "http://schemas.openxmlformats.org/package/2006/content-types";
15
16// DrawingML namespaces
17pub const DRAWING_ML: &str = "http://schemas.openxmlformats.org/drawingml/2006/main";
18pub const DRAWING_ML_CHART: &str = "http://schemas.openxmlformats.org/drawingml/2006/chart";
19pub const DRAWING_ML_SPREADSHEET: &str =
20    "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing";
21
22// Markup Compatibility
23pub const MC: &str = "http://schemas.openxmlformats.org/markup-compatibility/2006";
24
25// Dublin Core (document properties)
26pub const DC: &str = "http://purl.org/dc/elements/1.1/";
27pub const DC_TERMS: &str = "http://purl.org/dc/terms/";
28
29// Extended Properties
30pub const EXTENDED_PROPERTIES: &str =
31    "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties";
32pub const CORE_PROPERTIES: &str =
33    "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
34
35// Dublin Core DCMI Type
36pub const DC_MITYPE: &str = "http://purl.org/dc/dcmitype/";
37
38// VT Types (docProps)
39pub const VT: &str = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes";
40
41// Custom Properties
42pub const CUSTOM_PROPERTIES: &str =
43    "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties";
44
45// Slicer namespaces (Office 2010+ extensions)
46pub const SLICER_2009: &str = "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main";
47pub const SLICER_2010: &str = "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main";
48
49// XML standard
50pub const XML: &str = "http://www.w3.org/XML/1998/namespace";
51pub const XSI: &str = "http://www.w3.org/2001/XMLSchema-instance";
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn test_namespace_constants_are_valid_uris() {
59        // All namespace constants should be non-empty strings starting with http or urn
60        let namespaces = [
61            SPREADSHEET_ML,
62            RELATIONSHIPS,
63            PACKAGE_RELATIONSHIPS,
64            CONTENT_TYPES,
65            DRAWING_ML,
66            MC,
67            EXTENDED_PROPERTIES,
68            CORE_PROPERTIES,
69        ];
70        for ns in namespaces {
71            assert!(!ns.is_empty());
72            assert!(
73                ns.starts_with("http://") || ns.starts_with("urn:"),
74                "Namespace should start with http:// or urn: but got: {ns}"
75            );
76        }
77    }
78
79    #[test]
80    fn test_spreadsheet_ml_namespace() {
81        assert_eq!(
82            SPREADSHEET_ML,
83            "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
84        );
85    }
86
87    #[test]
88    fn test_relationships_namespace() {
89        assert_eq!(
90            RELATIONSHIPS,
91            "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
92        );
93    }
94
95    #[test]
96    fn test_content_types_namespace() {
97        assert_eq!(
98            CONTENT_TYPES,
99            "http://schemas.openxmlformats.org/package/2006/content-types"
100        );
101    }
102}