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// XML standard
46pub const XML: &str = "http://www.w3.org/XML/1998/namespace";
47pub const XSI: &str = "http://www.w3.org/2001/XMLSchema-instance";
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_namespace_constants_are_valid_uris() {
55        // All namespace constants should be non-empty strings starting with http or urn
56        let namespaces = [
57            SPREADSHEET_ML,
58            RELATIONSHIPS,
59            PACKAGE_RELATIONSHIPS,
60            CONTENT_TYPES,
61            DRAWING_ML,
62            MC,
63            EXTENDED_PROPERTIES,
64            CORE_PROPERTIES,
65        ];
66        for ns in namespaces {
67            assert!(!ns.is_empty());
68            assert!(
69                ns.starts_with("http://") || ns.starts_with("urn:"),
70                "Namespace should start with http:// or urn: but got: {ns}"
71            );
72        }
73    }
74
75    #[test]
76    fn test_spreadsheet_ml_namespace() {
77        assert_eq!(
78            SPREADSHEET_ML,
79            "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
80        );
81    }
82
83    #[test]
84    fn test_relationships_namespace() {
85        assert_eq!(
86            RELATIONSHIPS,
87            "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
88        );
89    }
90
91    #[test]
92    fn test_content_types_namespace() {
93        assert_eq!(
94            CONTENT_TYPES,
95            "http://schemas.openxmlformats.org/package/2006/content-types"
96        );
97    }
98}