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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*!
# Restricted XML parsing and encoding
This crate provides "restricted" parsing and encoding of XML 1.0 documents
with namespacing.
## Features (some call them restrictions)
* No external resources
* No custom entities
* No DTD whatsoever
* No processing instructions
* Optional (disabled-by-default) support for comments
* UTF-8 only
* Namespacing-well-formedness enforced
* XML 1.0 only
* Streamed parsing (parser emits a subset of SAX events)
* Streamed encoding
* Parser can be driven push- and pull-based
* Tokio-based asynchronicity supported (see [`AsyncReader`]).
See [`crate::_spec`] for additional documentation on what exactly
"restricted XML" means.
## Examples
### Parse data from byte slices
To parse a XML document from a byte slice (or a series of byte slices), you
can use the [`Parser`] with the [`Parse`] trait directly:
```
use rxml::{Parser, Parse, Error, Event, XmlVersion};
use std::io;
let mut doc = &b"<?xml version='1.0'?><hello>World!</hello>"[..];
let mut fp = Parser::new();
while doc.len() > 0 {
let ev = fp.parse(&mut doc, true); // true = doc contains the entire document
println!("got event: {:?}", ev);
}
```
### Parse data from a standard library reader
To parse a XML document from a [`std::io::BufRead`] struct, you can use the
[`Reader`].
*/
/*!
# use std::io::BufReader;
# let file = &mut &b"<?xml version='1.0'?><hello>World!</hello>"[..];
// let file = std::fs::File::open(..).unwrap();
let reader = BufReader::new(file);
let mut reader = rxml::Reader::new(reader);
let result = rxml::as_eof_flag(reader.read_all(|ev| {
println!("got event: {:?}", ev);
}));
assert_eq!(result.unwrap(), true); // true indicates eof
```
### Parse data using `tokio`
To parse a XML document from a [`tokio::io::AsyncBufRead`] struct, you can use
the [`AsyncReader`].
This requires the `tokio` feature.
*/
/*!
# use tokio::io::AsyncRead;
use rxml::{AsyncReader, Error, Event, XmlVersion};
# tokio_test::block_on(async {
# let sock = &mut &b"<?xml version='1.0'?><hello>World!</hello>"[..];
// let sock = ..;
let reader = tokio::io::BufReader::new(sock);
let mut reader = AsyncReader::new(reader);
// we expect the first event to be the XML declaration
let ev = reader.read().await;
assert!(matches!(ev, Ok(Some(Event::XmlDeclaration(_, XmlVersion::V1_0)))));
# })
```
## Feature flags
- `macros`: Enable macros to convert `&str` to `&NameStr` and `&NcNameStr`,
respectively.
- `compact_str` (default): Enable the use of
[`compact_str`](https://crates.io/crates/compact_str) for some string types
to avoid allocations and conserve heap memory.
- `tokio` (default): Enable `AsyncReader` and related types.
- `stream`: Add a `futures::Stream` implementation to `AsyncReader`. Implies
`tokio`.
- `shared_ns`: Allow deduplication of namespace URIs within and across
parsers.
- `std` (default): Enable `Reader` and related types which depend on
`std::io`.
- `extra-platforms`: Use the Arc implementation from
[`portable-atomic-util`](https://crates.io/crates/portable-atomic-util).
Note that `extra-platforms` and `shared_ns` cannot be enabled at the same
time currently. Enabling both will cause the `shared_ns` feature to be
implicitly and silently disabled.
*/
extern crate alloc;
extern crate std;
pub use Context;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use XmlLangTracker;
pub use ;
pub use rxml_proc;
pub use bytes;
/**
Compile-time conversion of a string literal to [`NameStr`]
Convert a string literal into a `NameStr`, while asserting its compliance
at compile time.
# Example
```rust
use rxml::{NameStr, xml_name};
const FORBIDDEN: &'static NameStr = xml_name!("xmlns:xml");
```
Invalid values are rejected at compile-time:
```rust,compile_fail
# use rxml::{NameStr, xml_name};
const INVALID: &'static NameStr = xml_name!("foo bar");
```
*/
/**
Compile-time conversion of a string literal to [`NcNameStr`]
Convert a string literal into a `NcNameStr`, while asserting its compliance
at compile time.
# Example
```rust
use rxml::{NcNameStr, xml_ncname};
const XML_PREFIX: &'static NcNameStr = xml_ncname!("xml");
```
Invalid values are rejected at compile-time:
```rust,compile_fail
# use rxml::{NcNameStr, xml_ncname};
const INVALID: &'static NcNameStr = xml_ncname!("xmlns:xml");
```
*/
pub use ;
/// Package version
pub const VERSION: &str = env!;