Develop and Download Open Source Software

Browse CVS Repository

Contents of /gikonavigoeson/gikonavi/GikoXMLDoc.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download) (as text)
Sat Oct 9 15:07:20 2004 UTC (19 years, 6 months ago) by yoffy
Branch: MAIN
CVS Tags: v1_59_0_771, v1_59_0_770, v1_59_0_773, v1_59_0_772, v1_59_0_775, v1_59_0_774, v1_59_0_777, v1_59_0_776, v1_56_0_715, v1_59_0_778, v1_63_1_819, v1_57_0_737, v1_62_0_812, v1_57_0_735, v1_57_0_734, v1_57_0_733, v1_57_0_732, v1_57_0_731, v1_57_0_730, v1_50_2_606, v1_51_0_612, v1_50_0_581, v1_50_0_580, v1_50_0_587, v1_50_0_586, v1_57_0_739, v1_57_0_738, v1_59_1_765, v1_51_1_639, v1_53_0_671, v1_50_0_595, v1_60_0_788, v1_60_0_789, v1_54_0_677, v1_54_0_676, v1_50_0_572, v1_58_0_748, marged-Bb50, v1_58_0_745, v1_60_0_781, v1_60_0_782, v1_58_0_746, v1_60_0_784, v1_54_0_678, v1_60_0_786, v1_60_0_787, v1_56_0_707, v1_59_0_767, v1_56_0_705, v1_56_0_704, v1_56_0_703, v1_56_0_702, v1_56_0_701, v1_56_0_700, v1_59_1_778, v1_51_0_626, v1_57_0_723, b51, v1_52_1_658, v1_51_0_622, v1_59_0_768, v1_59_0_769, v1_50_0_598, v1_57_0_725, v1_57_0_726, v1_57_0_727, v1_57_0_720, v1_57_0_722, v1_57_1_744, v1_50_0_590, bv1_49_0_564, v1_50_0_593, v1_57_0_728, v1_57_0_729, v1_50_0_596, bv1_49_0_563, v1_52_0_646, v1_50_0_557, v1_57_0_736, v1_50_0_585, v1_51_0_611, v1_51_0_620, v1_52_0_644, v1_58_0_752, v1_58_0_750, v1_58_0_751, v1_58_0_756, v1_58_0_757, v1_58_0_754, v1_58_0_755, v1_58_0_759, v1_52_0_643, v1_57_0_719, v1_57_0_718, v1_56_0_716, v1_54_0_687, v1_56_0_710, v1_56_0_711, v1_56_1_717, v1_56_1_716, v1_51_0_634, v1_51_0_635, v1_51_0_636, v1_51_0_637, v1_54_0_688, v1_54_0_689, v1_51_0_632, v1_51_0_633, v1_50_0_603, v1_54_0_684, v1_50_0_582, v1_54_0_685, v1_53_0_664, v1_61_0_796, v1_61_0_797, v1_61_0_795, v1_52_0_647, v1_61_0_798, v1_61_0_799, v1_50_0_604, v1_51_0_638, v1_52_0_648, v1_53_0_661, v1_53_0_663, v1_53_0_662, v1_53_0_665, v1_53_0_667, v1_53_0_666, v1_53_0_669, v1_53_0_668, v1_55_0_692, v1_55_0_693, v1_55_0_696, v1_55_0_697, v1_55_0_694, v1_55_0_695, merged-remodeling, v1_50_0_577, v1_52_0_645, v1_52_0_651, v1_54_1_691, v1_52_0_650, v1_56_2_724, v1_50_0_606, v1_56_2_722, v1_50_0_588, v1_52_0_652, v1_55_1_697, v1_52_0_642, v1_52_0_654, v1_51_0_616, v1_56_0_714, v1_51_0_614, v1_51_0_615, v1_53_0_672, v1_51_0_613, v1_53_0_670, v1_63_0_818, v1_63_0_817, v1_63_0_816, v1_63_0_815, v1_51_1_640, v1_54_0_686, v1_51_0_618, v1_51_0_619, bv1_49_0_565, v1_54_0_680, v1_54_0_681, v1_62_0_805, v1_62_0_804, v1_62_0_807, v1_62_0_806, b50, v1_56_0_712, v1_62_0_803, v1_62_0_802, v1_56_0_713, v1_62_0_809, v1_50_0_574, v1_54_0_682, v1_50_0_584, v_step1, v1_56_0_721, v1_50_0_573, v1_50_0_600, v1_51_0_630, v1_50_0_571, v1_54_0_683, v1_51_0_631, v1_60_0_780, v1_60_0_779, v1_62_0_810, v1_62_0_811, v1_58_0_747, v1_60_0_783, root-of-draw, v1_50_0_576, v1_54_0_679, v1_59_2_785, marged_bRESPOPUP, v1_50_2_604, v1_50_0_578, v1_54_0_675, v1_51_0_628, v1_50_0_579, v1_51_0_617, root-of-Bb50, root-of-Bb51, v1_56_0_706, root-of-remodel, root-of-Bb53, v1_50_0_594, v1_52_1_657, v1_54_0_674, v1_52_0_660, v1_60_1_793, v1_50_0_602, v1_51_0_629, v1_54_0_690, v1_51_0_627, v1_50_0_601, v1_58_0_763, v1_58_0_762, v1_58_0_761, v1_58_0_760, v1_51_0_625, v1_62_1_813, v1_51_0_623, v1_57_2_749, v1_50_0_605, v1_57_0_742, v1_57_0_743, v1_57_0_740, v1_57_0_741, v1_52_0_655, v1_56_0_709, v1_57_0_744, v1_52_0_656, v1_56_0_708, v1_52_0_649, v1_61_0_800, v1_53_1_673, v1_50_0_599, v1_56_0_699, v1_56_0_698, v1_50_0_561, v1_51_0_624, v1_51_1_641, v1_51_0_621, v1_60_0_793, v1_60_0_792, v1_60_0_791, v1_60_0_790, v1_60_2_794, v1_61_1_801, HEAD
Branch point for: Bb57, Bb56, Bb55, Bb53, Bb52, Bb51, Bb62, Bb63, Bb60, Bb61, remodeling, Bb59, Bb58, Bb50, bRESPOPUP, bListSU, Bb54, Bdraw
Changes since 1.9: +10 -7 lines
File MIME type: text/x-pascal
コメントつけかえ。

1 unit GikoXMLDoc;
2
3 {!
4 \file GikoXMLDoc.pas
5 \brief XMLIntf, XMLDoc ?????????????若??lt;br>
6 Delphi 6 Personal ??/span>
7
8 $Id$
9 }
10 interface
11
12 //==================================================
13 uses
14 //==================================================
15
16 Classes, SysUtils, Windows,
17 YofUtils;
18
19 //==================================================
20 type
21 //==================================================
22
23 // ??????????篏??c???????????違??????????
24 XMLDictionary = Record
25 Name : string;
26 Value : string;
27 end;
28
29 IXMLNode = class
30 private
31 FNodeName : string;
32 FCapacity : Integer;
33 FCount : Integer;
34 FAttributeCount : Integer;
35 FChildNodes : IXMLNode;
36 FNodes : array of IXMLNode;
37 FAttributes : array of XMLDictionary;
38 function GetAttribute( const Name : string ) : string;
39 function GetNode( Index : Integer ) : IXMLNode;
40 public
41 constructor Create;
42 destructor Destroy; override;
43
44 property NodeName : string read FNodeName write FNodeName;
45 property Attributes[ const Name : string ] : string read GetAttribute;
46 property Node[ Index : Integer ] : IXMLNode read GetNode; default;
47 property ChildNodes : IXMLNode read FChildNodes write FChildNodes;
48 property Count : Integer read FCount write FCount;
49 procedure Add( node : IXMLNode );
50 procedure AddAttribute( const Name : string; const Value : string );
51 end;
52
53 IXMLDocument = class( IXMLNode )
54 private
55 function GetDocumentElement() : IXMLNode;
56 public
57 property DocumentElement : IXMLNode read GetDocumentElement;
58 end;
59
60 function XMLCloseCheck(
61 var p : PChar;
62 const tail : PChar;
63 var node : IXMLNode;
64 out tag : string;
65 out closed : boolean // ?若?喝?冴???????若???潟?? node ?????????鴻?????? true
66 ) : boolean; // ch ?????????若???潟?????????????? true
67
68 function XMLReadNode(
69 var p : PChar;
70 const tail : PChar;
71 var node : IXMLNode
72 ) : string; // node 篁ュ??????若???????????????翫???????若????
73
74 procedure LoadXMLDocument(
75 const fileName : string;
76 var doc : IXMLDocument
77 );
78
79 //==================================================
80 const
81 //==================================================
82 kXMLWhite : TSysCharSet = [#0..#$20];
83 kXMLNodeNameStop : TSysCharSet = [#0..#$20, '/', '>'];
84 kXMLAttributeNameStop : TSysCharSet = [#0..#$20, '=', '/', '>'];
85 kXMLDQuote : TSysCharSet = ['"'];
86 kXMLTagStart : TSysCharSet = ['<'];
87 kXMLTagEnd : TSysCharSet = ['>'];
88 kXMLKanji : TSysCharSet = [#$81..#$9f, #$E0..#$fc];
89
90 //==================================================
91 implementation
92 //==================================================
93
94 // Constructor
95 constructor IXMLNode.Create;
96 begin
97
98 inherited;
99
100 FCapacity := 0;
101 FCount := 0;
102
103 end;
104
105 // Destructor
106 destructor IXMLNode.Destroy;
107 var
108 i : Integer;
109 begin
110
111 for i := FCount - 1 downto 0 do
112 FNodes[ i ].Free;
113 FChildNodes.Free;
114
115 inherited;
116
117 end;
118
119 function IXMLNode.GetAttribute( const Name : string ) : string;
120 var
121 i : Integer;
122 begin
123
124 i := 0;
125 while i < FAttributeCount do
126 begin
127 if Name = FAttributes[ i ].Name then
128 begin
129 Result := FAttributes[ i ].Value;
130 exit;
131 end;
132
133 Inc( i );
134 end;
135
136 end;
137
138 function IXMLNode.GetNode( Index : Integer ) : IXMLNode;
139 begin
140
141 Result := FNodes[ Index ];
142
143 end;
144
145 procedure IXMLNode.Add( node : IXMLNode );
146 begin
147
148 Inc( FCount );
149 if FCount > FCapacity then begin
150 FCapacity := FCapacity + (FCapacity shr 2) + 1;
151 SetLength( FNodes, FCapacity );
152 end;
153
154 FNodes[ FCount - 1 ] := node;
155
156 end;
157
158 procedure IXMLNode.AddAttribute(
159 const Name : string;
160 const Value : string
161 );
162 var
163 index : Integer;
164 begin
165
166 index := FAttributeCount;
167 Inc( FAttributeCount );
168 SetLength( FAttributes, FAttributeCount );
169
170 FAttributes[ index ].Name := Name;
171 FAttributes[ index ].Value := Value;
172
173 end;
174
175 function IXMLDocument.GetDocumentElement() : IXMLNode;
176 begin
177
178 Result := FChildNodes[ 0 ];
179
180 end;
181
182 {!
183 \brief tok ???≪??
184 \param p ?∝刈??紮?篏?臀?/span>
185 \param tail 腟?篋?篏?臀 + 1
186 \param tok ?≪?????c??????/span>
187 \return tok ??????????ゃ???c??篏?臀?/span>
188 }
189 function AnsiStrTok(
190 p : PChar;
191 const tail : PChar;
192 const tok : TSysCharSet
193 ) : PChar;
194 begin
195
196 while p < tail do
197 begin
198 if p^ in tok then
199 begin
200 Break;
201 end else if p^ in kXMLKanji then
202 p := p + 2
203 else
204 Inc( p );
205 end;
206
207 Result := p;
208
209 end;
210
211 {!
212 \brief tok ?с???<?????c?????帥???≪??
213 \param p ?∝刈??紮?篏?臀?/span>
214 \param tail 腟?篋?篏?臀 + 1
215 \param tok ?≪?????c??????/span>
216 \return tok ?с?????????c?????帥??????????ゃ???c??篏?臀?/span>
217 }
218 function AnsiStrNonTok(
219 p : PChar;
220 const tail : PChar;
221 const tok : TSysCharSet
222 ) : PChar;
223 begin
224
225 while p < tail do
226 begin
227 if p^ in tok then
228 begin
229 if p^ in kXMLKanji then
230 p := p + 2
231 else
232 Inc( p );
233 end else begin
234 Break;
235 end;
236 end;
237
238 Result := p;
239
240 end;
241
242 function XMLCloseCheck(
243 var p : PChar;
244 const tail : PChar;
245 var node : IXMLNode;
246 out tag : string;
247 out closed : boolean
248 ) : boolean; // ch ?????????若???潟?????????????? true
249 var
250 found : PChar;
251 begin
252
253 closed := false;
254 Result := false;
255 tag := '';
256
257 case p^ of
258 '>':
259 begin
260 // ??紮??帥?違????緇??障?ц?????
261 Inc( p ); // '>' 蕋??違??
262 Result := true;
263 end;
264
265 '?':
266 begin
267 // <?xml?> ?帥?????????ゃ?????c???∴?
268 p := AnsiStrTok( p, tail, kXMLTagEnd );
269 p := AnsiStrTok( p, tail, kXMLTagStart );
270 Inc( p ); // '<' 蕋??違??
271 p := AnsiStrNonTok( p, tail, kXMLWhite );
272 //closed := true;
273 Result := true;
274 end;
275
276 '/':
277 begin
278 // ?帥?医????茯??粋昭???ц???
279 Inc( p ); // '/' 蕋??違??
280 found := AnsiStrTok( p, tail, kXMLTagEnd );
281 // tag := Copy( p, 0, found - p ); // 篏?????羶???
282 SetLength( tag, found - p );
283 CopyMemory( PChar( tag ), p, found - p );
284
285 p := found + 1; // '>' 蕋??違??
286 closed := true;
287 Result := true;
288 end;
289 end;
290
291 end;
292
293 function XMLReadNode(
294 var p : PChar;
295 const tail : PChar;
296 var node : IXMLNode
297 ) : string; // node 篁ュ??????若???????????????翫???????若????
298 var
299 child : IXMLNode;
300
301 found : PChar;
302 tag : string;
303
304 isClosed : boolean;
305
306 nodeName : string;
307 attributeName : string;
308 attributeValue : string;
309 label
310 NextNode;
311 begin
312 try
313 // node ????粋昭??1 ???若?????ゃ?? 1 ???若??)
314 node.ChildNodes := IXMLNode.Create;
315
316 while p < tail do
317 begin
318 // NodeName 茯??粋昭??/span>
319 p := AnsiStrNonTok( p, tail, kXMLWhite );
320
321 while p < tail do
322 begin
323 if XMLCloseCheck( p, tail, node, tag, isClosed ) then
324 begin
325 if isClosed then
326 begin
327 Result := tag;
328 exit;
329 end;
330
331 goto NextNode;
332 end else if p^ = '<' then
333 begin
334 // ?域????若??
335 Inc( p );
336 child := IXMLNode.Create;
337 tag := XMLReadNode( p, tail, child );
338 node.ChildNodes.Add( child );
339
340 // ?帥?違????????????
341 if Length( tag ) > 0 then
342 begin
343 // ???????????????с???????????????域Κ?????
344 if tag <> node.NodeName then
345 Result := tag;
346 exit;
347 end;
348
349 goto NextNode;
350 end else if p^ in kXMLWhite then
351 begin
352 // NodeName 絎?篋?
353 break;
354 end else begin
355 found := AnsiStrTok( p, tail, kXMLNodeNameStop );
356 SetLength( nodeName, found - p );
357 CopyMemory( PChar( nodeName ), p, found - p );
358 node.NodeName := nodeName;
359
360 p := found;
361 end;
362 end;
363
364 // Attribute ????粋昭??/span>
365 while p < tail do
366 begin
367 // Attribute ????????茯??粋昭??/span>
368 attributeName := '';
369 attributeValue := '';
370
371 p := AnsiStrNonTok( p, tail, kXMLWhite );
372
373 while p < tail do
374 begin
375 if XMLCloseCheck( p, tail, node, tag, isClosed ) then
376 begin
377 if isClosed then
378 begin
379 // ?帥?違???????????????с???帥?若??/span>
380 // ??odeName ???????????????ч??筝??ч????????????????????
381 // ???c????????若????
382 exit;
383 end;
384
385 // 罨<?????若????/span>
386 goto NextNode;
387 end else if p^ = '=' then
388 begin
389 // ???????????ゃ??紮??障?????у???????篋?
390 Inc( p );
391 break;
392 end else if p^ in kXMLWhite then
393 begin
394 // Value ??絖?????????(荀?弱?)???ф??????若????/span>
395 goto NextNode;
396 end else begin
397 found := AnsiStrTok( p, tail, kXMLAttributeNameStop );
398 SetLength( attributeName, found - p );
399 CopyMemory( PChar( attributeName ), p, found - p );
400
401 p := found;
402 end;
403 end;
404
405 // Attribute ???ゃ??茯??粋昭??/span>
406 p := AnsiStrNonTok( p, tail, kXMLWhite );
407
408 while p < tail do
409 begin
410 if XMLCloseCheck( p, tail, node, tag, isClosed ) then
411 begin
412 if isClosed then
413 begin
414 if Length( attributeName ) > 0 then
415 // 荀?弱?????????/span>
416 node.AddAttribute( attributeName, attributeValue );
417
418 // ?帥?違???????????????с???帥?若??/span>
419 // ??odeName ???????????????ч??筝??ч????????????????????
420 // ???c????????若????
421 exit;
422 end;
423
424 // 罨<?????若????/span>
425 goto NextNode;
426 end else if p^ = '"' then
427 begin
428 // ?ゃ?? "" ?ф????????????????????????????????????????????????????
429 // ?ゃ??筝?????粋昭??/span>
430 Inc( p );
431 found := AnsiStrTok( p, tail, kXMLDQuote );
432 // attributeValue := Copy( p, 0, found - p ); // 篏?????羶???
433 SetLength( attributeValue, found - p );
434 CopyMemory( PChar( attributeValue ), p, found - p );
435
436 node.AddAttribute( attributeName, HtmlDecode( attributeValue ) );
437
438 // ?ゃ??茯??睡???c?????х?篋?
439 p := found + 1; // '"' 蕋??違??
440 break;
441 end else if p^ in kXMLWhite then
442 begin
443 // 荀?弱?????????/span>
444 node.AddAttribute( attributeName, HtmlDecode( attributeValue ) );
445
446 goto NextNode;
447 end else begin
448 // 荀?弱????????綽????c??????span>
449 attributeValue := attributeValue + p^;
450
451 if p^ in kXMLKanji then
452 begin
453 attributeValue := attributeValue + (p + 1)^;
454 p := p + 2;
455 end else begin
456 Inc( p );
457 end;
458 end;
459 end;
460 end; // Attribute ????粋昭??/span>
461
462 NextNode:;
463 end; // // node ????粋昭??1 ???若?????ゃ?? 1 ???若??)
464 finally
465 end;
466 end;
467
468 procedure LoadXMLDocument(
469 const fileName : string;
470 var doc : IXMLDocument
471 );
472 type
473 xmlMode = ( xmlHoge );
474 var
475 xmlFile : TMappedFile;
476 p : PChar;
477 begin
478 //Result := IXMLDocument.Create;
479 //doc := IXMLDocument.Create;
480
481 xmlFile := TMappedFile.Create( fileName );
482
483 try
484 p := xmlFile.Memory;
485 XMLReadNode( p, p + xmlFile.Size, IXMLNode( doc ) );
486 //XMLReadNode( xmlFile, IXMLNode( Result ) );
487 finally
488 xmlFile.Free;
489 end;
490
491 //Result := doc;
492
493 end;
494
495 end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26