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
145
146
147
148
149
150
/// XML support for reading and writing structured data.
///
/// This module provides components for reading data from XML files and writing data to XML files
/// as part of a batch processing pipeline. The implementation uses `quick-xml` for efficient
/// XML parsing and serialization.
///
/// # Features
///
/// - Read XML documents with support for complex nested structures
/// - Write data to XML files with customizable root and item tags
/// - Support for XML attributes via serde's `#[serde(rename = "@attribute_name")]`
/// - Automatic type inference for tag names
///
/// # Examples
///
/// ## Reading from XML
///
/// ```
/// use spring_batch_rs::item::xml::XmlItemReaderBuilder;
/// use spring_batch_rs::core::item::ItemReader;
/// use serde::Deserialize;
/// use std::io::Cursor;
///
/// // Define a data structure with XML attributes and nested elements
/// #[derive(Debug, Deserialize)]
/// struct Product {
/// #[serde(rename = "@id")]
/// id: String,
/// #[serde(rename = "@available")]
/// available: bool,
/// name: String,
/// price: f64,
/// #[serde(default)]
/// description: Option<String>,
/// }
///
/// // Sample XML data
/// let xml_data = r#"
/// <catalog>
/// <product id="P001" available="true">
/// <name>Wireless Headphones</name>
/// <price>79.99</price>
/// <description>Noise-cancelling wireless headphones with 20hr battery life</description>
/// </product>
/// <product id="P002" available="false">
/// <name>USB-C Cable</name>
/// <price>12.99</price>
/// </product>
/// </catalog>
/// "#;
///
/// // Create a reader from our XML
/// let cursor = Cursor::new(xml_data);
/// let reader = XmlItemReaderBuilder::<Product>::new()
/// .tag("product")
/// .from_reader(cursor);
///
/// // Read and process the products
/// let mut products = Vec::new();
/// while let Some(product) = reader.read().unwrap() {
/// products.push(product);
/// }
///
/// // Verify results
/// assert_eq!(products.len(), 2);
/// assert_eq!(products[0].id, "P001");
/// assert_eq!(products[0].name, "Wireless Headphones");
/// assert_eq!(products[0].price, 79.99);
/// assert!(products[0].available);
/// assert!(products[0].description.is_some());
///
/// assert_eq!(products[1].id, "P002");
/// assert_eq!(products[1].name, "USB-C Cable");
/// assert_eq!(products[1].price, 12.99);
/// assert!(!products[1].available);
/// assert!(products[1].description.is_none());
/// ```
///
/// ## Writing to XML
///
/// ```
/// use spring_batch_rs::item::xml::xml_writer::XmlItemWriterBuilder;
/// use spring_batch_rs::core::item::ItemWriter;
/// use serde::Serialize;
/// use std::io::Cursor;
///
/// // Define a data structure for serialization
/// #[derive(Serialize)]
/// struct Product {
/// #[serde(rename = "@id")]
/// id: String,
/// #[serde(rename = "@in_stock")]
/// in_stock: bool,
/// name: String,
/// price: f64,
/// categories: Vec<String>,
/// }
///
/// // Create some products
/// let products = vec![
/// Product {
/// id: "P001".to_string(),
/// in_stock: true,
/// name: "Smartphone".to_string(),
/// price: 599.99,
/// categories: vec!["Electronics".to_string(), "Mobile".to_string()],
/// },
/// Product {
/// id: "P002".to_string(),
/// in_stock: false,
/// name: "Laptop".to_string(),
/// price: 1299.99,
/// categories: vec!["Electronics".to_string(), "Computers".to_string()],
/// },
/// ];
///
/// // Create a writer with a memory buffer
/// let buffer = Cursor::new(Vec::new());
/// let writer = XmlItemWriterBuilder::<Product>::new()
/// .root_tag("catalog")
/// .item_tag("product")
/// .from_writer(buffer);
///
/// // Write the products to XML
/// writer.open().unwrap();
/// writer.write(&products).unwrap();
/// writer.close().unwrap();
///
/// // The resulting XML would look similar to:
/// // <catalog>
/// // <product id="P001" in_stock="true">
/// // <name>Smartphone</name>
/// // <price>599.99</price>
/// // <categories>Electronics</categories>
/// // <categories>Mobile</categories>
/// // </product>
/// // <product id="P002" in_stock="false">
/// // <name>Laptop</name>
/// // <price>1299.99</price>
/// // <categories>Electronics</categories>
/// // <categories>Computers</categories>
/// // </product>
/// // </catalog>
/// ```
pub use ;
pub use XmlItemWriter;
pub use XmlItemWriterBuilder;