This file is indexed.

/usr/share/doc/tclxml/tclxml.html is in tclxml 3.3~svn11-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TclXML</title>
<link rel="stylesheet" href="tclxml.css">
</head>
<body><div class="refentry">
<h1 class="title"><a name="idm47916199161136">TclXML</a></h1>
<h2>Contents</h2>
<ul>
<li><a href="#synopsis">Synopsis</a></li>
<li><a href="#idm47916198831536">Description</a></li>
<li>
<a href="#idm47916198824832">Commands</a><ul>
<li>
<a href="#idm47916198823472">::xml::parserclass</a><ul><li><a href="#idm47916198820448">Command Options</a></li></ul>
</li>
<li>
<a href="#idm47916198793328">::xml::parser</a><ul>
<li><a href="#idm47916198771440">Configuration Options</a></li>
<li><a href="#idm47916198394672">Parser Command</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#idm47916198293216">Callback Return Codes</a></li>
<li><a href="#idm47916198283392">Error Messages</a></li>
<li><a href="#idm47916198258240">Application Examples</a></li>
<li><a href="#idm47916198253664">Safe XML</a></li>
<li>
<a href="#idm47916198249808">Parser Classes</a><ul>
<li><a href="#idm47916198247888">Tcl Parser Class</a></li>
<li>
<a href="#idm47916198243712">libxml2 Parser Class</a><ul>
<li><a href="#idm47916198239264">get Method</a></li>
<li><a href="#idm47916198233808">Additional Options</a></li>
<li><a href="#idm47916198218784">Limitations</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#idm47916198211056">Keywords</a></li>
</ul>
<div class="refnamediv">
<span class="refname">TclXML</span> ? <span class="refpurpose">XML parser support for Tcl</span>
</div>
<div class="refsynopsisdiv">
<a name="synopsis"></a><h2>Synopsis</h2>
<div class="cmdsynopsis" id="idm47916198849920">
<a name="idm47916198849920"></a><span class="command" id="idm47916198849552"><a name="package_require_xml"></a><tt>package require xml</tt> </span>
</div>
<div class="cmdsynopsis" id="idm47916198848896">
<a name="idm47916198848896"></a><span class="command" id="idm47916198848528"><a name="package_require_parserclass"></a><tt>package require <em>parserclass</em></tt> </span>
</div>
<br><span class="pkgsynopsis"><pre>package require xml ?3.3?</pre></span><div class="cmdsynopsis" id="idm47916198843728">
<a name="idm47916198843728"></a><span class="command" id="idm47916198843360"><a name="__xml__parserclass"></a><tt>::xml::parserclass</tt> </span> <em>option</em> ?arg arg...?</div>
<div class="cmdsynopsis" id="idm47916198840112">
<a name="idm47916198840112"></a><span class="command" id="idm47916198839744"><a name="__xml__parser"></a><tt>::xml::parser</tt> </span> ?<em>name</em>? ? <em>-option</em><em>value</em>...?</div>
<div class="cmdsynopsis" id="idm47916198835488">
<a name="idm47916198835488"></a><span class="command" id="idm47916198835120"><a name="parser"></a><tt><em>parser</em></tt> </span><em>option</em> <em>arg</em>
</div>
<h3>Tcl Namespace Usage</h3>
<br><tt>::xml</tt><br><tt>::sgml</tt><br><tt>::xml::tclparser</tt><br><tt>::xml::libxml2</tt><p></p>
</div>
<div class="refsect1">
<h2>
<a name="idm47916198831536"></a>Description</h2>
<p>TclXML provides event-based parsing of <a href="http://www.w3.org/XML/">XML</a> documents.  The application may register callback scripts for certain document features, and when the parser encounters those features while parsing the document the callback is evaluated.</p>
<p>The parser may also perform other functions, such as normalisation, validation and/or entity expansion.  Generally, these functions are under the control of configuration options.  Whether these functions can be performed at all depends on the parser implementation.</p>
<p>The TclXML package provides a generic interface for use by a Tcl application, along with a low-level interface for use by a parser implementation.  Each implementation provides a class of XML parser, and these register themselves using the <strong>::xml::parserclass create</strong> command.  One of the registered parser classes will be the default parser class.</p>
<p>Loading the package with the generic <strong>package require xml</strong> command allows the package to automatically determine the default parser class.  In order to select a particular parser class as the default, that class' package may be loaded directly, eg. <strong>package require xml::libxml2</strong>.  In all cases, all available parser classes are registered with the TclXML package, the difference is simply in which one becomes the default.</p>
</div>
<div class="refsect1">
<h2>
<a name="idm47916198824832"></a>Commands</h2>
<div class="refsect2">
<h3>
<a name="idm47916198823472"></a><strong>::xml::parserclass</strong>
</h3>
<p>The <strong>::xml::parserclass</strong> command is used to manage XML parser classes.</p>
<div class="refsect3">
<h4>
<a name="idm47916198820448"></a>Command Options</h4>
<p>The following command options may be used:</p>
<dl>
<span class="term"><span class="methodname">create</span></span><dd>
<div class="cmdsynopsis" id="idm47916198816880">
<a name="idm47916198816880"></a>create <em>name</em> ? <em>-createcommand</em><em>script</em>? ? <em>-createentityparsercommand</em><em>script</em>? ? <em>-parsecommand</em><em>script</em>? ? <em>-configurecommand</em><em>script</em>? ? <em>-getcommand</em><em>script</em>? ? <em>-deletecommand</em><em>script</em>?</div>
<p>Creates an XML parser class with the given name.</p>
</dd>
<span class="term"><span class="methodname">destroy</span></span><dd>
<div class="cmdsynopsis" id="idm47916198800688">
<a name="idm47916198800688"></a>destroy <em>name</em>
</div>
<p>Destroys an XML parser class.</p>
</dd>
<span class="term"><span class="methodname">info</span></span><dd>
<div class="cmdsynopsis" id="idm47916198796848">
<a name="idm47916198796848"></a><tt>::xml::parserclass</tt> <u>info</u> names default</div>
<p>Returns information about registered XML parser classes.</p>
</dd>
</dl>
</div>
</div>
<div class="refsect2">
<h3>
<a name="idm47916198793328"></a><strong>::xml::parser</strong>
</h3>
<p>The <strong>::xml::parser</strong> command creates an <em>XML</em> parser object.  The return value of the command is the name of the newly created parser.</p>
<p>The parser scans an XML document's syntactical structure, evaluating callback scripts for each feature found.  At the very least the parser will normalise the document and check the document for well-formedness.  If the document is not well-formed then the  <em>-errorcommand</em> option will be evaluated.  Some parser classes may perform additional functions, such as validation.  Additional features provided by the various parser classes are described in the section Parser Classes</p>
<p>Parsing is performed synchronously.  The command blocks until the entire document has been parsed.  Parsing may be terminated by an application callback, see the section Callback Return Codes.  Incremental parsing is also supported by using the  <em>-final</em> configuration option.</p>
<div class="refsect3">
<h4>
<a name="idm47916198771440"></a>Configuration Options</h4>
<p>The <strong>::xml::parser</strong> command accepts the following configuration options:</p>
<dl>
<span class="term"> <em>-attlistdeclcommand</em></span><dd>
<p><tt>-attlistdeclcommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated whenever an attribute list declaration is encountered in the DTD subset of an XML document.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198765104">
<a name="idm47916198765104"></a><tt><em>script</em></tt> <em>name</em> <em>attrname</em> <em>type</em> <em>default</em> <em>value</em>
</div>
<p>where:</p>
<table border="0">
<tr>
<td valign="top"> <tt><em>name</em></tt>
</td>
<td valign="top">Element type name</td>
</tr>
<tr>
<td valign="top"> <tt><em>attrname</em></tt>
</td>
<td valign="top">Attribute name being declared</td>
</tr>
<tr>
<td valign="top"> <tt><em>type</em></tt>
</td>
<td valign="top">Attribute type</td>
</tr>
<tr>
<td valign="top"> <tt><em>default</em></tt>
</td>
<td valign="top">Attribute default, such as #IMPLIED</td>
</tr>
<tr>
<td valign="top"> <tt><em>value</em></tt>
</td>
<td valign="top">Default attribute value.  Empty string if none given.</td>
</tr>
</table>
</dd>
<span class="term"> <em>-baseuri</em></span><span class="term"> <em>-baseurl</em></span><dd>
<p><tt>-baseuri</tt> <u><em>URI</em></u></p>
<p><tt>-baseurl</tt> <u><em>URI</em></u></p>
<p>Specifies the base URI for resolving relative URIs that may be used in the XML document to refer to external entities.</p>
<p> <em>-baseurl</em> is deprecated in favour of  <em>-baseuri</em>.</p>
</dd>
<span class="term"> <em>-characterdatacommand</em></span><dd>
<p><tt>-characterdatacommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated whenever character data is encountered in the XML document being parsed.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198737008">
<a name="idm47916198737008"></a><tt><em>script</em></tt> <em>data</em>
</div>
<p>where:</p>
<table border="0"><tr>
<td valign="top"> <tt><em>data</em></tt>
</td>
<td valign="top">Character data in the document</td>
</tr></table>
</dd>
<span class="term"> <em>-commentcommand</em></span><dd>
<p><tt>-commentcommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated whenever a comment is encountered in the XML document being parsed.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198728064">
<a name="idm47916198728064"></a><tt><em>script</em></tt> <em>data</em>
</div>
<p>where:</p>
<table border="0"><tr>
<td valign="top"> <tt><em>data</em></tt>
</td>
<td valign="top">Comment data</td>
</tr></table>
</dd>
<span class="term"> <em>-defaultcommand</em></span><dd>
<p><tt>-defaultcommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when no other callback has been defined for a document feature which has been encountered.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198719136">
<a name="idm47916198719136"></a><tt><em>script</em></tt> <em>data</em>
</div>
<p>where:</p>
<table border="0"><tr>
<td valign="top"> <tt><em>data</em></tt>
</td>
<td valign="top">Document data</td>
</tr></table>
</dd>
<span class="term"> <em>-defaultexpandinternalentities</em></span><dd>
<p><tt>-defaultexpandinternalentities</tt> <u><em>boolean</em></u></p>
<p>Specifies whether entities declared in the internal DTD subset are expanded with their replacement text.  If entities are not expanded then the entity references will be reported with no expansion.</p>
</dd>
<span class="term"> <em>-doctypecommand</em></span><dd>
<p><tt>-doctypecommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when the document type declaration is encountered.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198686384">
<a name="idm47916198686384"></a><tt><em>script</em></tt> <em>name</em> <em>public</em> <em>system</em> <em>dtd</em>
</div>
<p>where:</p>
<table border="0">
<tr>
<td valign="top"> <tt><em>name</em></tt>
</td>
<td valign="top">The name of the document element</td>
</tr>
<tr>
<td valign="top"> <tt><em>public</em></tt>
</td>
<td valign="top">Public identifier for the external DTD subset</td>
</tr>
<tr>
<td valign="top"> <tt><em>system</em></tt>
</td>
<td valign="top">System identifier for the external DTD subset.  Usually a URI.</td>
</tr>
<tr>
<td valign="top"> <tt><em>dtd</em></tt>
</td>
<td valign="top">The internal DTD subset</td>
</tr>
</table>
<p>See also  <em>-startdoctypedeclcommand</em> and  <em>-enddoctypedeclcommand</em>.</p>
</dd>
<span class="term"> <em>-elementdeclcommand</em></span><dd>
<p><tt>-elementdeclcommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when an element markup declaration is encountered.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198667584">
<a name="idm47916198667584"></a><tt><em>script</em></tt> <em>name</em> <em>model</em>
</div>
<p>where:</p>
<table border="0">
<tr>
<td valign="top"> <tt><em>name</em></tt>
</td>
<td valign="top">The element type name</td>
</tr>
<tr>
<td valign="top"> <tt><em>model</em></tt>
</td>
<td valign="top">Content model specification</td>
</tr>
</table>
</dd>
<span class="term"> <em>-elementendcommand</em></span><dd>
<p><tt>-elementendcommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when an element end tag is encountered.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198655760">
<a name="idm47916198655760"></a><tt><em>script</em></tt> <em>name</em> <em>args</em>
</div>
<p>where:</p>
<table border="0">
<tr>
<td valign="top"> <tt><em>name</em></tt>
</td>
<td valign="top">The element type name that has ended</td>
</tr>
<tr>
<td valign="top"> <tt><em>args</em></tt>
</td>
<td valign="top">Additional information about this element</td>
</tr>
</table>
<p>Additional information about the element takes the form of configuration options.  Possible options are:</p>
<table border="0">
<tr>
<td valign="top"> <em>-empty</em> <tt><em>boolean</em></tt>
</td>
<td valign="top">The empty element syntax was used for this element</td>
</tr>
<tr>
<td valign="top"> <em>-namespace</em> <tt><em>uri</em></tt>
</td>
<td valign="top">The element is in the XML namespace associated with the given URI</td>
</tr>
</table>
</dd>
<span class="term"> <em>-elementstartcommand</em></span><dd>
<p><tt>-elementstartcommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when an element start tag is encountered.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198638016">
<a name="idm47916198638016"></a><tt><em>script</em></tt> <em>name</em> <em>attlist</em> <em>args</em>
</div>
<p>where:</p>
<table border="0">
<tr>
<td valign="top"> <tt><em>name</em></tt>
</td>
<td valign="top">The element type name that has started</td>
</tr>
<tr>
<td valign="top"> <tt><em>attlist</em></tt>
</td>
<td valign="top">A Tcl list containing the attributes for this element.  The list of attributes is formatted as pairs of attribute names and their values.  </td>
</tr>
<tr>
<td valign="top"> <tt><em>args</em></tt>
</td>
<td valign="top">Additional information about this element</td>
</tr>
</table>
<p>Additional information about the element takes the form of configuration options.  Possible options are:</p>
<table border="0">
<tr>
<td valign="top"> <em>-empty</em> <tt><em>boolean</em></tt>
</td>
<td valign="top">The empty element syntax was used for this element</td>
</tr>
<tr>
<td valign="top"> <em>-namespace</em> <tt><em>uri</em></tt>
</td>
<td valign="top">The element is in the XML namespace associated with the given URI</td>
</tr>
<tr>
<td valign="top"> <em>-namespacedecls</em> <tt><em>list</em></tt>
</td>
<td valign="top">The start tag included one or more XML Namespace declarations.   <tt><em>list</em></tt> is a Tcl list giving the namespaces declared.  The list is formatted as pairs of values, the first value is the namespace URI and the second value is the prefix used for the namespace in this document.  A default XML namespace declaration will have an empty string for the prefix.</td>
</tr>
</table>
</dd>
<span class="term"> <em>-encoding</em></span><dd>
<p><tt>-encoding</tt> <u><em>value</em></u></p>
<p>Gives the character encoding of the document.  This option only has an effect before a document is parsed.  The default character encoding is <span class="literal">utf-8</span>.  If the value <span class="literal">unknown</span> is given, or any value other than <span class="literal">utf-8</span>, then the document text is treated as binary data.  If the value is given as <span class="literal">unknown</span> then the parser will attempt to automatically determine the character encoding of the document (using byte-order-marks, etc).  If any value other than <span class="literal">utf-8</span> or <span class="literal">unknown</span> is given then the parser will read the document text using that character encoding.</p>
</dd>
<span class="term"> <em>-endcdatasectioncommand</em></span><dd>
<p><tt>-endcdatasectioncommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when end of a CDATA section is encountered.  The command is evaluated with no further arguments.</p>
</dd>
<span class="term"> <em>-enddoctypedeclcommand</em></span><dd>
<p><tt>-enddoctypedeclcommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when end of the document type declaration is encountered.  The command is evaluated with no further arguments.</p>
</dd>
<span class="term"> <em>-entitydeclcommand</em></span><dd>
<p><tt>-entitydeclcommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when an entity declaration is encountered.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198599360">
<a name="idm47916198599360"></a><tt><em>script</em></tt> <em>name</em> <em>args</em>
</div>
<p>where:</p>
<table border="0">
<tr>
<td valign="top"> <tt><em>name</em></tt>
</td>
<td valign="top">The name of the entity being declared</td>
</tr>
<tr>
<td valign="top"> <tt><em>args</em></tt>
</td>
<td valign="top">Additional information about the entity declaration.  An internal entity shall have a single argument, the replacement text.  An external parsed entity shall have two additional arguments, the public and system indentifiers of the external resource.  An external unparsed entity shall have three additional arguments, the public and system identifiers followed by the notation name.</td>
</tr>
</table>
</dd>
<span class="term"> <em>-entityreferencecommand</em></span><dd>
<p><tt>-entityreferencecommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when an entity reference is encountered.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198708336">
<a name="idm47916198708336"></a><tt><em>script</em></tt> <em>name</em>
</div>
<p>where:</p>
<table border="0"><tr>
<td valign="top"> <tt><em>name</em></tt>
</td>
<td valign="top">The name of the entity being referenced</td>
</tr></table>
</dd>
<span class="term"> <em>-errorcommand</em></span><dd>
<p><tt>-errorcommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when a fatal error is detected.  The error may be due to the XML document not being well-formed.  In the case of a validating parser class, the error may also be due to the XML document not obeying validity constraints.  By default, a callback script is provided which causes an error return code, but an application may supply a script which attempts to continue parsing.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198699088">
<a name="idm47916198699088"></a><tt><em>script</em></tt> <em>errorcode</em> <em>errormsg</em>
</div>
<p>where:</p>
<table border="0">
<tr>
<td valign="top"> <tt><em>errorcode</em></tt>
</td>
<td valign="top">A single word description of the error, intended for use by an application</td>
</tr>
<tr>
<td valign="top"> <tt><em>errormsg</em></tt>
</td>
<td valign="top">A human-readable description of the error</td>
</tr>
</table>
</dd>
<span class="term"> <em>-externalentitycommand</em></span><dd>
<p><tt>-externalentitycommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated to resolve an external entity reference.  If the parser has been configured to validate the XML document, a default script is supplied that resolves the URI given as the system identifier of the external entity and recursively parses the entity's data.  If the parser has been configured as a non-validating parser, then by default external entities are not resolved.  This option can be used to override the default behaviour.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198544864">
<a name="idm47916198544864"></a><tt><em>script</em></tt> <em>name</em> <em>baseuri</em> <em>uri</em> <em>id</em>
</div>
<p>where:</p>
<table border="0">
<tr>
<td valign="top"> <tt><em>name</em></tt>
</td>
<td valign="top">The Tcl command name of the current parser</td>
</tr>
<tr>
<td valign="top"> <tt><em>baseuri</em></tt>
</td>
<td valign="top">An absolute URI for the current entity which is to be used to resolve relative URIs</td>
</tr>
<tr>
<td valign="top"> <tt><em>uri</em></tt>
</td>
<td valign="top">The system identifier of the external entity, usually a URI</td>
</tr>
<tr>
<td valign="top"> <tt><em>id</em></tt>
</td>
<td valign="top">The public identifier of the external entity.  If no public identifier was given in the entity declaration then  <tt><em>id</em></tt> will be an empty string.</td>
</tr>
</table>
<p>The return result of the callback script determines the action of the parser.  Note that these codes are interpreted in a different manner to other callbacks.</p>
<dl>
<span class="term"><span class="literal">TCL_OK</span></span><dd>
<p>The return result of the callback script is used as the external entity's data.  The URI passed to the callback script is used as the entity's base URI.</p>
<p>This is useful to either override the normal loading of an entity's data, or to implement new or alternative URI schemes.  As an example, the script below sets an external entity handler that intercepts "tcl:" URIs and evaluates them as inline Tcl scripts:</p>
<div class="informalexample"><pre><div class="programlisting"><pre>
package require xml

proc External {name baseuri uri id} {
    switch -glob -- $uri {
	tcl:* {
	    regexp {^tcl:(.*)$} $uri discard script
	    return [uplevel #0 $script]
	}
	default {
	    return -code continue {}
	}
    }
}

set parser [xml::parser -externalentitycommand External]
$parser parse {&lt;!DOCTYPE example [
  &lt;!ENTITY example SYSTEM "tcl:set%20example%20HelloWorld"&gt;
]&gt;
&lt;example&gt;
  &amp;example;
&lt;/example&gt;
}

puts $example
</pre></div></pre></div>
<p>This script will print "HelloWorld" to stdout.</p>
</dd>
<span class="term"><span class="literal">TCL_CONTINUE</span></span><dd>
<p>In a normal (non-safe) interpreter, the default external entity handler is used to load the external entity data as per normal operation of the parser.  If the parser is executing in a Safe Tcl interpreter then the entity is not loaded at all.</p>
<p>This is useful to interpose on the loading of external entities without interfering with the loading of entities.</p>
</dd>
<span class="term"><span class="literal">TCL_BREAK</span></span><dd><p>No data is returned for this entity, ie. the entity is ignored.  No error is propagated.</p></dd>
<span class="term"><span class="literal">TCL_ERROR</span></span><dd><p>No data is returned for this entity, ie. the entity is ignored.  A background error is registered, using the result of the callback script.</p></dd>
</dl>
</dd>
<span class="term"> <em>-final</em></span><dd>
<p><tt>-final</tt> <u><em>boolean</em></u></p>
<p>Specifies whether the XML document being parsed is complete.  If the document is to be incrementally parsed then this option will be set to false, and when the last fragment of document is parsed it is set to true.  For example,</p>
<div class="informalexample"><pre><div class="programlisting"><pre>
set parser [::xml::parser -final 0]
$parser parse $data1
.
.
.
$parser parse $data2
.
.
.
$parser configure -final 1
$parser parse $finaldata
		</pre></div></pre></div>
</dd>
<span class="term"> <em>-ignorewhitespace</em></span><dd>
<p><tt>-ignorewhitespace</tt> <u><em>boolean</em></u></p>
<p>If this option is set to true then spans of character data in the XML document which are composed only of white-space (CR, LF, space, tab) will not be reported to the application.  In other words, the data passed to every invocation of the  <em>-characterdatacommand</em> script will contain at least one non-white-space character.</p>
</dd>
<span class="term"> <em>-notationdeclcommand</em></span><dd>
<p><tt>-notationdeclcommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when a notation declaration is encountered.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198504688">
<a name="idm47916198504688"></a><tt><em>script</em></tt> <em>name</em> <em>uri</em>
</div>
<p>where:</p>
<table border="0">
<tr>
<td valign="top"> <tt><em>name</em></tt>
</td>
<td valign="top">The name of the notation</td>
</tr>
<tr>
<td valign="top"> <tt><em>uri</em></tt>
</td>
<td valign="top">An external identifier for the notation, usually a URI.</td>
</tr>
</table>
</dd>
<span class="term"> <em>-notstandalonecommand</em></span><dd>
<p><tt>-notstandalonecommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when the parser determines that the XML document being parsed is not a standalone document.</p>
</dd>
<span class="term"> <em>-paramentityparsing</em></span><dd>
<p><tt>-paramentityparsing</tt> <u><em>boolean</em></u></p>
<p>Controls whether external parameter entities are parsed.</p>
</dd>
<span class="term"> <em>-parameterentitydeclcommand</em></span><dd>
<p><tt>-parameterentitydeclcommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when a parameter entity declaration is encountered.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198484848">
<a name="idm47916198484848"></a><tt><em>script</em></tt> <em>name</em> <em>args</em>
</div>
<p>where:</p>
<table border="0">
<tr>
<td valign="top"> <tt><em>name</em></tt>
</td>
<td valign="top">The name of the parameter entity</td>
</tr>
<tr>
<td valign="top"> <tt><em>args</em></tt>
</td>
<td valign="top">For an internal parameter entity there is only one additional argument, the replacement text.  For external parameter entities there are two additional arguments, the system and public identifiers respectively.</td>
</tr>
</table>
</dd>
<span class="term"> <em>-parser</em></span><dd>
<p><tt>-parser</tt> <u><em>name</em></u></p>
<p>The name of the parser class to instantiate for this parser object.  This option may only be specified when the parser instance is created.</p>
</dd>
<span class="term"> <em>-processinginstructioncommand</em></span><dd>
<p><tt>-processinginstructioncommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when a processing instruction is encountered.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198468368">
<a name="idm47916198468368"></a><tt><em>script</em></tt> <em>target</em> <em>data</em>
</div>
<p>where:</p>
<table border="0">
<tr>
<td valign="top"> <tt><em>target</em></tt>
</td>
<td valign="top">The name of the processing instruction target</td>
</tr>
<tr>
<td valign="top"> <tt><em>data</em></tt>
</td>
<td valign="top">Remaining data from the processing instruction</td>
</tr>
</table>
</dd>
<span class="term"> <em>-reportempty</em></span><dd>
<p><tt>-reportempty</tt> <u><em>boolean</em></u></p>
<p>If this option is enabled then when an element is encountered that uses the special empty element syntax, additional arguments are appended to the  <em>-elementstartcommand</em> and  <em>-elementendcommand</em> callbacks.  The arguments <span class="arg">-empty 1</span> are appended.  For example:</p>
<div class="cmdsynopsis" id="idm47916198455232">
<a name="idm47916198455232"></a><tt><em>script</em></tt>  <em>-empty</em>1</div>
</dd>
<span class="term"> <em>-startcdatasectioncommand</em></span><dd>
<p><tt>-startcdatasectioncommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when the start of a CDATA section section is encountered.  No arguments are appended to the script.</p>
</dd>
<span class="term"> <em>-startdoctypedeclcommand</em></span><dd>
<p><tt>-startdoctypedeclcommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated at the start of a document type declaration.  No arguments are appended to the script.</p>
</dd>
<span class="term"> <em>-unknownencodingcommand</em></span><dd>
<p><tt>-unknownencodingcommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when a character is encountered with an unknown encoding.  This option has not been implemented.</p>
</dd>
<span class="term"> <em>-unparsedentitydeclcommand</em></span><dd>
<p><tt>-unparsedentitydeclcommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when a declaration is encountered for an unparsed entity.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198436688">
<a name="idm47916198436688"></a><tt><em>script</em></tt> <em>system</em> <em>public</em> <em>notation</em>
</div>
<p>where:</p>
<table border="0">
<tr>
<td valign="top"> <tt><em>system</em></tt>
</td>
<td valign="top">The system identifier of the external entity, usually a URI</td>
</tr>
<tr>
<td valign="top"> <tt><em>public</em></tt>
</td>
<td valign="top">The public identifier of the external entity</td>
</tr>
<tr>
<td valign="top"> <tt><em>notation</em></tt>
</td>
<td valign="top">The name of the notation for the external entity</td>
</tr>
</table>
</dd>
<span class="term"> <em>-validate</em></span><dd>
<p><tt>-validate</tt> <u><em>boolean</em></u></p>
<p>Enables validation of the XML document to be parsed.  Any changes to this option are ignored after an XML document has started to be parsed, but the option may be changed after a reset.</p>
</dd>
<span class="term"> <em>-warningcommand</em></span><dd>
<p><tt>-warningcommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when a warning condition is detected.  A warning condition is where the XML document has not been authored correctly, but is still well-formed and may be valid.  For example, the special empty element syntax may be used for an element which has not been declared to have empty content.  By default, a callback script is provided which silently ignores the warning.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198417680">
<a name="idm47916198417680"></a><tt><em>script</em></tt> <em>warningcode</em> <em>warningmsg</em>
</div>
<p>where:</p>
<table border="0">
<tr>
<td valign="top"> <tt><em>warningcode</em></tt>
</td>
<td valign="top">A single word description of the warning, intended for use by an application</td>
</tr>
<tr>
<td valign="top"> <tt><em>wanringmsg</em></tt>
</td>
<td valign="top">A human-readable description of the warning</td>
</tr>
</table>
</dd>
<span class="term"> <em>-xmldeclcommand</em></span><dd>
<p><tt>-xmldeclcommand</tt> <u><em>script</em></u></p>
<p>Specifies the prefix of a Tcl command to be evaluated when the XML declaration is encountered.  The command evaluated is:</p>
<div class="cmdsynopsis" id="idm47916198405840">
<a name="idm47916198405840"></a><tt><em>script</em></tt> <em>version</em> <em>encoding</em> <em>standalone</em>
</div>
<p>where:</p>
<table border="0">
<tr>
<td valign="top"> <tt><em>version</em></tt>
</td>
<td valign="top">The version number of the XML specification to which this document purports to conform</td>
</tr>
<tr>
<td valign="top"> <tt><em>encoding</em></tt>
</td>
<td valign="top">The character encoding of the document</td>
</tr>
<tr>
<td valign="top"> <tt><em>standalone</em></tt>
</td>
<td valign="top">A boolean declaring whether the document is standalone</td>
</tr>
</table>
</dd>
</dl>
</div>
<div class="refsect3">
<h4>
<a name="idm47916198394672"></a>Parser Command</h4>
<p>The <strong>::xml::parser</strong> command creates a new Tcl command with the same name as the parser.  This command may be used to invoke various operations on the parser object.  It has the following general form:</p>
<div class="cmdsynopsis" id="idm47916198392048">
<a name="idm47916198392048"></a><tt><em>name</em></tt>  <em><em>option</em></em><em>arg</em>
</div>
<p> <em><em>option</em></em> and the <span class="arg"><em>arg</em></span> determine the exact behaviour of the command.  The following commands are possible for parser objects:</p>
<dl>
<span class="term"> <em>cget</em></span><dd>
<div class="cmdsynopsis" id="idm47916198568896">
<a name="idm47916198568896"></a><tt><i>name</i></tt> <u>cget</u><em>-option</em>
</div>
<p>Returns the current value of the configuration option given by  <em><em>option</em></em>.   <em><em>Option</em></em> may have any of the values accepted by the parser object.</p>
</dd>
<span class="term"> <em>configure</em></span><dd>
<div class="cmdsynopsis" id="idm47916198564064">
<a name="idm47916198564064"></a><tt><i>name</i></tt> <u>configure</u> "<em>-option</em> <em>value</em>..."</div>
<p>Modify the configuration options of the parser object.   <em><em>Option</em></em> may have any of the values accepted by the parser object.</p>
</dd>
<span class="term"> <em>entityparser</em></span><dd>
<div class="cmdsynopsis" id="idm47916198558352">
<a name="idm47916198558352"></a><tt><i>name</i></tt> <u>entityparser</u> "<em>option</em> <em>value</em>..."</div>
<p>Creates a new parser object.  The new object inherits the same configuration options as the parent parser object, but is able to parse XML data in a parsed entity.  The option  <em>-dtdsubset</em> allows markup declarations to be treated as being in the internal or external DTD subset.</p>
</dd>
<span class="term"> <em>free</em></span><dd>
<div class="cmdsynopsis" id="idm47916198308928">
<a name="idm47916198308928"></a><tt><i>name</i></tt> <u>free</u><em>name</em>
</div>
<p>Frees all resources associated with the parser object.  The object is not usable after this command has been invoked.</p>
</dd>
<span class="term"> <em>get</em></span><dd>
<div class="cmdsynopsis" id="idm47916198305216">
<a name="idm47916198305216"></a><tt><i>name</i></tt> <u>get</u><em>name</em> args</div>
<p>Returns information about the XML document being parsed.  Each parser class provides different information, see the documentation for the parser class.</p>
</dd>
<span class="term"> <em>parse</em></span><dd>
<div class="cmdsynopsis" id="idm47916198300384">
<a name="idm47916198300384"></a><tt><i>name</i></tt> <u>parse</u><em>xml</em> args</div>
<p>Parses the XML document.  The usual desired effect is for various application callbacks to be evaluated.  Other functions will also be performed by the parser class, at the very least this includes checking the XML document for well-formedness.</p>
</dd>
<span class="term"> <em>reset</em></span><dd>
<div class="cmdsynopsis" id="idm47916198295360">
<a name="idm47916198295360"></a><tt><i>name</i></tt> <u>reset</u>
</div>
<p>Initialises the parser object in preparation for parsing a new XML document.</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="refsect1">
<h2>
<a name="idm47916198293216"></a>Callback Return Codes</h2>
<p>Every callback script evaluated by a parser may return a return code other than <span class="arg">TCL_OK</span>.  Return codes are interpreted as follows:</p>
<table border="0">
<tr>
<td valign="top">break</td>
<td valign="top">Suppresses invocation of all further callback scripts.  The  <em>parse</em> method returns the  <tt>TCL_OK</tt> return code.</td>
</tr>
<tr>
<td valign="top">continue</td>
<td valign="top">Suppresses invocation of further callback scripts until the current element has finished.</td>
</tr>
<tr>
<td valign="top">error</td>
<td valign="top">Suppresses invocation of all further callback scripts.  The  <em>parse</em> method also returns the  <tt>TCL_ERROR</tt> return code.</td>
</tr>
<tr>
<td valign="top">default</td>
<td valign="top">Any other return code suppresses invocation of all further callback scripts.  The  <em>parse</em> method returns the same return code.</td>
</tr>
</table>
</div>
<div class="refsect1">
<h2>
<a name="idm47916198283392"></a>Error Messages</h2>
<p>If an error or warning condition is detected then an error message is returned.  These messages are structured as a Tcl list, as described below:</p>
<div class="informalexample"><pre><div class="programlisting"><pre>{domain level code node line message int1 int2 string1 string2 string3}</pre></div></pre></div>
<dl>
<span class="term"><span class="literal">domain</span></span><dd><p>A code for the subsystem that detected the error.</p></dd>
<span class="term"><span class="literal">level</span></span><dd><p>Severity level of the problem.</p></dd>
<span class="term"><span class="literal">code</span></span><dd><p>A one word string describing the error.</p></dd>
<span class="term"><span class="literal">node</span></span><dd><p>If available, the token of the DOM node associated with the problem.</p></dd>
<span class="term"><span class="literal">line</span></span><dd><p>If known, the line number in the source XML document where the problem was detected.</p></dd>
<span class="term"><span class="literal">message</span></span><dd><p>A human-readable description of the problem.</p></dd>
<span class="term"><span class="literal">int1</span></span><dd><p>Additional integer data.  For the parser domain, this is usually the column number where the problem was detected.</p></dd>
<span class="term"><span class="literal">int2</span></span><dd><p>Additional integer data.</p></dd>
<span class="term"><span class="literal">string1</span></span><dd><p>Additional string data.</p></dd>
<span class="term"><span class="literal">string2</span></span><dd><p>Additional string data.</p></dd>
<span class="term"><span class="literal">string3</span></span><dd><p>Additional string data.</p></dd>
</dl>
</div>
<div class="refsect1">
<h2>
<a name="idm47916198258240"></a>Application Examples</h2>
<p>This script outputs the character data of an XML document read from stdin.</p>
<div class="informalexample"><pre><div class="programlisting"><pre>
package require xml

proc cdata {data args} {
    puts -nonewline $data
}

set parser [::xml::parser -characterdatacommand cdata]
$parser parse [read stdin]
      </pre></div></pre></div>
<p>This script counts the number of elements in an XML document read from stdin.</p>
<div class="informalexample"><pre><div class="programlisting"><pre>
package require xml

proc EStart {varName name attlist args} {
    upvar #0 $varName var
    incr var
}

set count 0
set parser [::xml::parser -elementstartcommand [list EStart count]]
$parser parse [read stdin]
puts "The XML document contains $count elements"
      </pre></div></pre></div>
</div>
<div class="refsect1">
<h2>
<a name="idm47916198253664"></a>Safe XML</h2>
<p>TclXML/Tcl and TclXML/libxml2 may be used in a Safe Tcl interpreter.  When a document is parsed in a Safe Tcl interpreter, any attempt by the XML document to load an external entity is handled by the -externalentitycommand callback.  This callback is evaluated in the context of the safe interpreter and therefore is subject to the security policy in force for that interpreter.  The default entity loader will not be invoked, even if the callback script returns a <span class="literal">TCL_CONTINUE</span> code.</p>
<p>See the description of the -externalentitycommand for further details.</p>
</div>
<div class="refsect1">
<h2>
<a name="idm47916198249808"></a>Parser Classes</h2>
<p>This section will discuss how a parser class is implemented.</p>
<div class="refsect2">
<h3>
<a name="idm47916198247888"></a>Tcl Parser Class</h3>
<p>The pure-Tcl parser class requires no compilation - it is a collection of Tcl scripts.  This parser implementation is non-validating, ie. it can only check well-formedness in a document.  However, by enabling the  <em>-validate</em> option it will read the document's DTD and resolve external entities.  This parser class is referred to as TclXML/tcl.</p>
<p>This parser implementation aims to implement XML v1.0 and supports XML Namespaces.</p>
<p>Generally the parser produces XML Infoset information items.  That is, it gives the application a slightly higher-level view than the raw XML syntax.  For example, it does not report CDATA Sections.</p>
<p>TclXML/tcl is not able to handle character encodings other than UTF-8.</p>
</div>
<div class="refsect2">
<h3>
<a name="idm47916198243712"></a>libxml2 Parser Class</h3>
<p>The libxml2 parser class provides a Tcl interface to the libxml2 XML parser library.  This parser class is referred to as TclXML/libxml2.</p>
<p>When the package is loaded the variable <span class="literal">::xml::libxml2::libxml2version</span> is set to the version number of the libxml2 library being used.</p>
<p>On MS Windows, it is necessary to load the generic XML package first, and then the TclXML/libxml2 package.  For example,</p>
<div class="informalexample"><pre><div class="programlisting"><pre>
package require xml
package require xml::libxml2
</pre></div></pre></div>
<div class="refsect3">
<h4>
<a name="idm47916198239264"></a>get Method</h4>
<p>TclXML/libxml2 provides the following arguments to the get method:</p>
<dl>
<span class="term"><span class="arg">document</span></span><dd>
<p>Returns the parsed document object.  libxml2 builds an in-memory data structure of the XML document it parses (a DOM tree).  This method returns a handle (or token) for that structure.</p>
<p>TclXML/libxml2 manages the document object as a Tcl object.  See the  <em>-keep</em> for further information.</p>
</dd>
</dl>
</div>
<div class="refsect3">
<h4>
<a name="idm47916198233808"></a>Additional Options</h4>
<dl>
<span class="term"> <em>-keep</em></span><dd>
<p><tt>-keep</tt> <u>normal | implicit</u></p>
<p>Controls how the TclXML/libxml2 packages manages the document object.  The default value is <span class="literal">implicit</span>; the document is destroyed when the Tcl Object's internal representation is freed.  If the option is given the value <span class="literal">normal</span> then the document must be explicit destroyed.  The only way to explicitly destroy the document is by using the C API.</p>
</dd>
<span class="term"> <em>-retainpath</em></span><dd>
<p><tt>-retainpath</tt> <u><em>xpath</em></u></p>
<p>The given XPath location path specifies which part of the document is to be kept after the parsing operation has completed.  By default, all document data is discard after it has been parsed.</p>
</dd>
<span class="term"> <em>-retainpathns</em></span><dd>
<p><tt>-retainpathns</tt> <u><em>prefix ns ...</em></u></p>
<p>The value of this option is a list of pairs of XML Namespace prefixes and their corresponding namespace URIs.  These are used by the XPath location path given in the <span class="arg">-retainpath</span> option.</p>
</dd>
</dl>
</div>
<div class="refsect3">
<h4>
<a name="idm47916198218784"></a>Limitations</h4>
<p>The libxml2 parser classes has the following limitations:</p>
<ul>
<li><p> <em>-reportempty</em> has no effect.  libxml2 does not report empty element syntax.</p></li>
<li><p>Incremental (push) parsing, ie. <span class="arg"> <em>-final</em> <span class="literal">0</span></span> is not supported.</p></li>
<li><p>TclXML/libxml2 does not provide (DTD) validation, (WXS) schema validation or Relax NG validation, although the libxml2 library does provide those functions.  These functions are provided by the TclDOM/libxml2 package, but only in a "posteriori" fashion (ie. only after the document has been parsed).</p></li>
<li><p>libxml2 supports XML Namespaces.  The use of XML Namespaces can be queried, but the <em>declaration</em> of a XML Namespace is not reported.</p></li>
</ul>
</div>
</div>
</div>
<div class="refsect1">
<h2>
<a name="idm47916198211056"></a>Keywords</h2>
<div class="keywordset">XML, parse</div>
</div>
</div></body>
</html>