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 | with
ada.unchecked_Deallocation;
package body XML.Writer
is
Depth: Natural;
procedure Free is new ada.Unchecked_Deallocation (Attributes_t,
Attributes_view);
procedure Start_Document (F: in ada.Text_IO.File_Type)
is
begin
ada.Text_IO.Put_Line (F, "<?xml version=""1.0"" standalone=""yes""?>");
Depth := 0;
end Start_Document;
procedure End_Document (F: in ada.Text_IO.File_Type)
is
begin
null;
end End_Document;
procedure Start (F: in ada.Text_IO.File_Type;
Name: in String;
Atts: in Attributes_view)
is
begin
for Pad in 1 .. Depth
loop
ada.Text_IO.Put (F, " ");
end loop;
Depth := Depth + 1;
ada.Text_IO.Put (F, "<" & Name);
for Att in Atts'Range
loop
ada.Text_IO.Put (F, " " & to_String (Atts (Att).Name) & "=""" &
to_String (Atts (Att).Value) & """");
end loop;
ada.Text_IO.Put_Line (F, ">");
end Start;
procedure Start (F: in ada.Text_IO.File_Type;
Name: in unbounded_String;
Atts: in Attributes_view)
is
begin
Start (F, to_String (Name), Atts);
end Start;
procedure Finish (F: in ada.Text_IO.File_Type;
Name: in String)
is
begin
Depth := Depth - 1;
for Pad in 1 .. Depth
loop
ada.Text_IO.Put (F, " ");
end loop;
ada.Text_IO.Put_Line (F, "</" & Name & ">");
end Finish;
procedure Finish (F: in ada.Text_IO.File_Type;
Name: in unbounded_String)
is
begin
Finish (F, to_String (Name));
end Finish;
procedure Empty (F: in ada.Text_IO.File_Type;
Name: in String;
Atts: in Attributes_view)
is
begin
for Pad in 1 .. Depth
loop
ada.Text_IO.Put (F, " ");
end loop;
ada.Text_IO.Put (F, "<" & Name);
for Att in Atts'Range
loop
ada.Text_IO.Put (F, " " & to_String (Atts (Att).Name) & "=""" &
to_String (Atts (Att).Value) & """");
end loop;
ada.Text_IO.Put_Line (F, "/>");
end Empty;
procedure Empty (F: in ada.Text_IO.File_Type;
Name: in unbounded_String;
Atts: in Attributes_view)
is
begin
Empty (F, to_String (Name), Atts);
end Empty;
function "+" (K, V: in String) return Attribute_t
is
begin
return Attribute_t'(to_unbounded_String (K),
to_unbounded_String (V));
end "+";
function "+" (K, V: in String) return Attributes_view
is
begin
return new Attributes_t'(1 => Attribute_t'(to_unbounded_String (K),
to_unbounded_String (V)));
end "+";
function "+" (K: in unbounded_String;
V: in String) return Attribute_t
is
begin
return Attribute_t'(K, to_unbounded_String (V));
end "+";
function "+" (K: in unbounded_String;
V: in String) return Attributes_view
is
begin
return new Attributes_t'(1 => Attribute_t' (K, to_unbounded_String (V)));
end "+";
function "+" (K: in String;
V: in unbounded_String) return Attribute_t
is
begin
return Attribute_t'(to_unbounded_String (K), V);
end "+";
function "+" (K: in String;
V: in unbounded_String) return Attributes_view
is
begin
return new Attributes_t'(1 => Attribute_t'(to_unbounded_String (K), V));
end "+";
function MkAtt (L, R: in Attribute_t) return Attributes_view
is
begin
return new Attributes_t'(L, R);
end MkAtt;
function "&" (L, R: in Attribute_t) return Attributes_view
is
begin
return new Attributes_t'(L, R);
end "&";
function "&" (L: in Attributes_view; R: in Attribute_t) return Attributes_view
is
Result: Attributes_view;
ByeBye: Attributes_view;
begin
Result := new Attributes_t (1 .. L'Length + 1);
Result (1 .. L'Length) := L.all;
Result (L'Length + 1) := R;
ByeBye := L;
Free (ByeBye);
return Result;
end "&";
end XML.Writer;
|