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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//! XML serialization and deserialization for FHIR resources.
//!
//! This module provides streaming XML support through custom `serde::Serializer` and
//! `serde::Deserializer` implementations that convert between FHIR resources and XML
//! without materializing a full JSON intermediate representation.
//!
//! ## Architecture
//!
//! The XML implementation uses a streaming approach:
//!
//! - **Serialization**: Custom `Serializer` receives serialize calls as the FhirSerde macro
//! traverses the resource, buffers minimally to detect FHIR patterns (field/_field pairs),
//! and writes quick-xml events directly to output.
//!
//! - **Deserialization**: Custom `Deserializer` reads quick-xml events from input, uses
//! one-event lookahead to detect arrays, and reconstructs FHIR JSON patterns (field/_field)
//! on-the-fly for the FhirSerde macro.
//!
//! ## FHIR JSON ↔ XML Mapping
//!
//! The implementation handles FHIR's unique serialization patterns:
//!
//! ### Primitives with Extensions
//!
//! **JSON Pattern**:
//! ```json
//! {
//! "birthDate": "1974-12-25",
//! "_birthDate": {
//! "id": "bd1",
//! "extension": [...]
//! }
//! }
//! ```
//!
//! **XML Pattern**:
//! ```xml
//! <birthDate id="bd1" value="1974-12-25">
//! <extension url="...">...</extension>
//! </birthDate>
//! ```
//!
//! ### Simple Primitives
//!
//! **JSON Pattern**:
//! ```json
//! { "active": true }
//! ```
//!
//! **XML Pattern**:
//! ```xml
//! <active value="true"/>
//! ```
//!
//! ### Arrays
//!
//! **JSON Pattern**:
//! ```json
//! { "given": ["John", "Doe"] }
//! ```
//!
//! **XML Pattern**:
//! ```xml
//! <given value="John"/>
//! <given value="Doe"/>
//! ```
//!
//! ### Arrays with Extensions
//!
//! **JSON Pattern**:
//! ```json
//! {
//! "given": ["Alice", null],
//! "_given": [null, {"id": "g1"}]
//! }
//! ```
//!
//! **XML Pattern**:
//! ```xml
//! <given value="Alice"/>
//! <given id="g1"/>
//! ```
//!
//! ### Complex Objects
//!
//! **JSON Pattern**:
//! ```json
//! {
//! "code": {
//! "coding": [...]
//! }
//! }
//! ```
//!
//! **XML Pattern**:
//! ```xml
//! <code>
//! <coding>...</coding>
//! </code>
//! ```
//!
//! ## Special Attributes
//!
//! Three XML attributes have special meaning in FHIR:
//!
//! - **`value`**: The primitive value of an element
//! - **`id`**: Element identifier (from `_field` in JSON)
//! - **`url`**: Used in extensions and references
//!
//! All other data is represented as child elements.
//!
//! ## Namespace Handling
//!
//! - FHIR namespace (`http://hl7.org/fhir`) is added to the root resource element
//! - XHTML namespace (`http://www.w3.org/1999/xhtml`) is used for `<div>` elements
//! containing narrative text
//!
//! ## Examples
//!
//! ```ignore
//! use helios_serde::xml::{to_xml_string, from_xml_str};
//! use helios_fhir::r4::Patient;
//!
//! // Serialize to XML
//! let patient = Patient {
//! id: Some("example".to_string()),
//! active: Some(true.into()),
//! ..Default::default()
//! };
//! let xml = to_xml_string(&patient)?;
//!
//! // Deserialize from XML
//! let patient: Patient = from_xml_str(&xml)?;
//! ```
// Re-export serialization functions
pub use ;
// Re-export deserialization functions
pub use ;