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
/*!
# Restricted XML 1.0 parsing facilities
This module contains parsing facilities for XML documents. To satisfy
different styles of tree building, the parsing step is separated in two
stages: the logical stage and the namespace/attribute resolution stage.
## Logical stage
In the logical stage, the logical elements of the XML document are emitted as
[`RawEvent`] structs. These *may* be used by end-users to build XML document
models, but they are not completely validated even to the XML 1.0
specification. The caveats are documented at the [`RawParser`] struct.
## Namespace/attribute resolution stage
This stage resolves namespace declarations found in a stream of [`RawEvent`]
structs and emits [`Event`] structs.
Together with the validation of the logical stage, this provides full
conformity checks according to XML 1.0 and Namespaces for XML 1.0. Both stages
are combined in the [`Parser`] struct.
The downside of using this stage is added processing cost, because
considerable dynamic allocations need to be performed per-element (for
attribute hash maps). In addition, information about the prefixes used to
declare namespaces is lost (but nothing should rely on those anyway).
*/
pub use *;
pub use ;
pub use ;
use NamespaceResolver;
/**
# Non-blocking restricted XML 1.0 parser
The [`Parser`] allows parsing XML documents as they arrive in the application,
giving back control to the caller immediately when not enough data is available
for processing. This is especially useful when streaming data from sockets.
To read events from the `Parser` after feeding data, use its [`Parse`] trait.
## Example
```
use rxml::{Parser, Parse, Error, Event, XmlVersion, error::EndOrError};
let doc = b"<?xml version='1.0'?><hello>World!</hello>";
let mut fp = Parser::new();
// We expect a NeedMoreData, because the XML declaration is not complete yet
assert!(matches!(
fp.parse(&mut &doc[..10], false).err().unwrap(),
EndOrError::NeedMoreData,
));
// Now we pass the XML declaration (and some), so we expect a corresponding
// event
let ev = fp.parse(&mut &doc[10..25], false);
assert!(matches!(ev.unwrap().unwrap(), Event::XmlDeclaration(_, XmlVersion::V1_0)));
```
In contrast to a [`RawParser`], the [`Parser`] enforces well-formedness and
namespace-well-formedness.
[`rxml`]: crate
*/