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
#![cfg_attr(feature = "unstable", feature(pattern))]
#![cfg_attr(feature = "unstable", feature(test))]
extern crate typed_arena;
#[macro_use]
extern crate peresil;
use std::fmt;
mod str_ext;
mod lazy_hash_map;
mod string_pool;
mod raw;
mod str;
#[doc(hidden)]
pub mod thindom;
pub mod dom;
pub mod parser;
pub mod writer;
pub use str::XmlChar;
static XML_NS_PREFIX: &'static str = "xml";
static XML_NS_URI: &'static str = "http://www.w3.org/XML/1998/namespace";
#[derive(Debug,Copy,Clone,PartialEq,Eq,PartialOrd,Ord)]
pub struct PrefixedName<'a> {
prefix: Option<&'a str>,
local_part: &'a str,
}
impl<'a> PrefixedName<'a> {
pub fn new(local_part: &str) -> PrefixedName {
PrefixedName::with_prefix(None, local_part)
}
pub fn with_prefix(prefix: Option<&'a str>, local_part: &'a str) -> PrefixedName<'a> {
PrefixedName {
prefix: prefix,
local_part: local_part,
}
}
pub fn prefix(&self) -> Option<&str> { self.prefix }
pub fn local_part(&self) -> &str { self.local_part }
}
#[derive(Debug,Copy,Clone,PartialEq)]
pub struct QName<'s> {
namespace_uri: Option<&'s str>,
local_part: &'s str,
}
impl<'s> QName<'s> {
pub fn new(local_part: &'s str) -> QName<'s> {
QName::with_namespace_uri(None, local_part)
}
pub fn with_namespace_uri(namespace_uri: Option<&'s str>, local_part: &'s str) -> QName<'s> {
QName {
namespace_uri: namespace_uri,
local_part: local_part,
}
}
pub fn namespace_uri(&self) -> Option<&'s str> { self.namespace_uri }
pub fn local_part(&self) -> &'s str { self.local_part }
}
impl<'s> From<(&'s str, &'s str)> for QName<'s> {
fn from(v: (&'s str, &'s str)) -> QName<'s> {
QName { namespace_uri: Some(v.0), local_part: v.1 }
}
}
impl<'s> From<&'s str> for QName<'s> {
fn from(v: &'s str) -> QName<'s> {
QName { namespace_uri: None, local_part: v }
}
}
pub struct Package {
storage: raw::Storage,
connections: raw::Connections,
}
impl Package {
pub fn new() -> Package {
let s = raw::Storage::new();
let root = s.create_root();
Package {
storage: s,
connections: raw::Connections::new(root),
}
}
pub fn as_document(&self) -> dom::Document {
dom::Document::new(&self.storage, &self.connections)
}
#[doc(hidden)]
pub fn as_thin_document(&self) -> (thindom::Storage, thindom::Connections) {
let s = thindom::Storage::new(&self.storage);
let c = thindom::Connections::new(&self.connections);
(s, c)
}
}
impl PartialEq for Package {
fn eq(&self, other: &Package) -> bool {
self as *const Package == other as *const Package
}
}
impl fmt::Debug for Package {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Package")
}
}