tDOM

Check-in [f189f4695e]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merged from schema.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | virtualConstraints
Files: files | file ages | folders
SHA3-256: f189f4695e78e1d74a6f36fa9e259da0959e81f2785e85d621be44e83b175990
User & Date: rolf 2019-03-07 00:05:22
Context
2019-03-07
01:48
Save work. check-in: ba4f23dbc4 user: rolf tags: virtualConstraints
00:05
Merged from schema. check-in: f189f4695e user: rolf tags: virtualConstraints
2019-03-06
22:47
Further work on calling schema commands in schema definition / text constraint scripts. check-in: 2d5a4f85c8 user: rolf tags: schema
2019-02-19
23:06
Allow schema definition command "tcl" only inside of sequential content particles. Still uncertain about the interface. check-in: 23f4f6f626 user: rolf tags: virtualConstraints
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to doc/schema.html.

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
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
...
229
230
231
232
233
234
235
236
237
238
239
240

241
242
243
244
245
246
247
248
...
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
...
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
...
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
...
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
<html>
<head>
<link rel="stylesheet" href="manpage.css"><title>tDOM manual: schema</title><meta name="xsl-processor" content="Jochen Loewer ([email protected]), Rolf Ade ([email protected]) et. al."><meta name="generator" content="$RCSfile: tmml-html.xsl,v $ $Revision: 1.11 $"><meta charset="utf-8">
</head><body>
<div class="header">
<div class="navbar" align="center">
<a href="#SECTid0x15681d0">NAME</a> · <a href="#SECTid0x14a8260">SYNOPSIS</a> · <a href="#SECTid0x1612380">DESCRIPTION </a> · <a href="#SECTid0x161a570">Schema definition scripts</a> · <a href="#SECTid0x1621550">Quantity specifier</a> · <a href="#SECTid0x16233e0">Text constraint scripts</a> · <a href="#SECTid0x1625670">Exampels</a>
</div><hr class="navsep">
</div><div class="body">
  <h2><a name="SECTid0x15681d0">NAME</a></h2><p class="namesection">
<b class="names">tdom::schema - </b><br>Create a schema validation command</p>

  <h2><a name="SECTid0x14a8260">SYNOPSIS</a></h2><pre class="syntax">package require tdom

<b class="cmd">tdom::schema</b> <i class="m">?create?</i> <i class="m">cmdName</i>
    </pre>

  <h2><a name="SECTid0x1612380">DESCRIPTION </a></h2><p>This command creates validation commands with a simple API. The
    validation commands have methods to define a schema and are able
    to validate XML or DOM trees (and to some degree other kind of
    hierarchical data) against this schema.</p><p>Additionally, a validation command may be used as argument to
    the <i class="m">-validateCmd</i> option of the <i class="m">dom parse</i> and the
    <i class="m">expat</i> commands to enable validation additional to what they
    otherwise do.</p><p>The valid methods of the created commands are:</p><dl class="commandlist">
      
................................................................................
        <dt><b class="method">reset</b></dt>
        <dd>This method resets the validation command into state
        READY (while preserving the defined grammer).</dd>
      

    </dl>

  <h2><a name="SECTid0x161a570">Schema definition scripts</a></h2><p>Schema definition scripts are ordinary Tcl scripts that are
    evaluatend in the namespace tdom::schema. The below listed schema
    definition commands in this tcl namespace allow to define a wide
    variety of document structures. Every schema definition command
    establish a validation constraint on the content which has to
    match or must be optional to render the content as valid. It is a
    validation error if the element in the XML source has additional
    (not matched) content.</p><p>The schema definition commands are:</p><dl class="commandlist">
................................................................................
<b class="method">mixed</b> <i class="m">?quant?</i> <i class="m">&lt;definition script&gt;</i>
</dt>
        <dd></dd>
      

      
        <dt>
<b class="method">text</b> <i class="m">?&lt;constraint script&gt;?</i>
</dt>
        <dd>Without the optional constraint script this validation
        constraint matches every string (including the empty one).
        With <i class="m">constraint script</i> argument a text matching this

        script is expected.</dd>
      

      
        <dt>
<b class="method">any</b> <i class="m">?quant?</i>
</dt>
        <dd>The any command matches every element (with whatever
................................................................................
        or not. Please notice, that this mean the quantifier * and +
        will eat up any elements until the enclosing element
        ends.</dd>
      

      
        <dt>
<b class="method">attribute</b> <i class="m">name</i> <i class="m">?quant?</i> <i class="m">?&lt;constraint script&gt;?</i>
</dt>
        <dd></dd>











      

      
        <dt>
<b class="method">nsattribute</b> <i class="m">name</i> <i class="m">namespace</i> <i class="m">?quant?</i> <i class="m">?&lt;constraint script&gt;?</i>
</dt>
        <dd></dd>
      

      
        <dt>
<b class="method">namespace</b> <i class="m">uri</i> <i class="m">&lt;definition script&gt;</i>
</dt>
        <dd>Evaluates the <i class="m">definition script</i> with context namespace <i class="m">uri</i>.</dd>
      
      
      
        <dt>
<b class="method">defelement</b> <i class="m">name</i> <i class="m">?namespace?</i> <i class="m">&lt;definition script&gt;</i>
</dt>



        <dd>This command is not allowed nested in an other definition script command.</dd>

      

      
        <dt>
<b class="method">defpattern</b> <i class="m">name</i> <i class="m">?namespace?</i> <i class="m">&lt;definition script&gt;</i>
</dt>



        <dd>This command is not allowed nested in an other definition script command.</dd>

      

      
        <dt>
<b class="method">start</b> <i class="m">name</i> <i class="m">?namespace?</i>
</dt>


        <dd>This command is not allowed nested in an other definition script command.</dd>


      
    </dl>

  <h2><a name="SECTid0x1621550">Quantity specifier</a></h2><p>Serveral schema definition commands expects a quantifier as
    one of their arguments, which specifies how often the content
    particle specified by the command is expected. The valid values
    for a <i class="m">quant</i> argument are:</p><dl class="optlist">
      
        <dt><b>!</b></dt>
        <dd>The content particle must occur exactly once in valid
        documents. This is the default, if a quantifier is
................................................................................
        n to m times (both inclusive) in a row in valid documents. The
        quantifier must be a tcl list with two elements. Both elements
        must be integers, with n &gt;= 0 and n &lt; m.</dd>
      
    </dl><p>If an optional quantifier is not given then it defaults to * in
    case of the mixed command and to ! for all other commands.</p>

  <h2><a name="SECTid0x16233e0">Text constraint scripts</a></h2><p></p><p>The text constraint commands are:</p><dl class="commandlist">
      
        <dt><b class="cmd">isint</b></dt>
        <dd></dd>
      

      
        <dt>
................................................................................
        <dd></dd>
      
      
      
        <dt>
<b class="cmd">tcl</b> <i class="m">tclcmd</i> <i class="m">?arg arg ...?</i>
</dt>
        <dd></dd>


      
      
        <dt>
<b class="cmd">enumeration</b> <i class="m">list</i>
</dt>



        <dd></dd>
      
      
        <dt>
<b class="cmd">match</b> <i class="m">glob style match pattern</i>
</dt>








        <dd></dd>


      
      
        <dt><b class="cmd">nmtoken</b></dt>



        <dd></dd>
      
      
        <dt><b class="cmd">nmtokens</b></dt>







        <dd></dd>














































      
    </dl>
  
  <h2><a name="SECTid0x1625670">Exampels</a></h2><p>The XML Schema Part 0: Primer Second Edition
    (<a href="https://www.w3.org/TR/xmlschema-0/">https://www.w3.org/TR/xmlschema-0/</a>) starts with this
    example schema:</p><pre class="example">
&lt;xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;

  &lt;xsd:annotation&gt;
    &lt;xsd:documentation xml:lang="en"&gt;
     Purchase order schema for Example.com.
................................................................................
            attribute partNum ! {text {pattern "\d{3}-[A-Z]{2}"}}
        }
    }
}
      
    </pre><p>The RELAX NG Tutorial
    (<a href="http://relaxng.org/tutorial-20011203.html">http://relaxng.org/tutorial-20011203.html</a>) starts with
    this example:</p><pre class="example">
Consider a simple XML representation of an email address book:

&lt;addressBook&gt;
  &lt;card&gt;
    &lt;name&gt;John Smith&lt;/name&gt;
    &lt;email&gt;[email protected]&lt;/email&gt;
  &lt;/card&gt;





|


|


|




|







 







|







 







|



|
>
|







 







|

|
>
>
>
>
>
>
>
>
>
>
>




|

|






|






>
>
>
|
>






>
>
>
|
>






>
>
|
>
>



|







 







|







 







|
>
>





>
>
>
|



|

>
>
>
>
>
>
>
>
|
>
>



>
>
>
|



>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



|







 







|







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
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
...
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
...
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
...
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
...
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
...
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
<html>
<head>
<link rel="stylesheet" href="manpage.css"><title>tDOM manual: schema</title><meta name="xsl-processor" content="Jochen Loewer ([email protected]), Rolf Ade ([email protected]) et. al."><meta name="generator" content="$RCSfile: tmml-html.xsl,v $ $Revision: 1.11 $"><meta charset="utf-8">
</head><body>
<div class="header">
<div class="navbar" align="center">
<a href="#SECTid0x256b2d0">NAME</a> · <a href="#SECTid0x256b930">SYNOPSIS</a> · <a href="#SECTid0x256d440">DESCRIPTION </a> · <a href="#SECTid0x2576900">Schema definition scripts</a> · <a href="#SECTid0x257ec30">Quantity specifier</a> · <a href="#SECTid0x2580ac0">Text constraint scripts</a> · <a href="#SECTid0x2586740">Exampels</a>
</div><hr class="navsep">
</div><div class="body">
  <h2><a name="SECTid0x256b2d0">NAME</a></h2><p class="namesection">
<b class="names">tdom::schema - </b><br>Create a schema validation command</p>

  <h2><a name="SECTid0x256b930">SYNOPSIS</a></h2><pre class="syntax">package require tdom

<b class="cmd">tdom::schema</b> <i class="m">?create?</i> <i class="m">cmdName</i>
    </pre>

  <h2><a name="SECTid0x256d440">DESCRIPTION </a></h2><p>This command creates validation commands with a simple API. The
    validation commands have methods to define a schema and are able
    to validate XML or DOM trees (and to some degree other kind of
    hierarchical data) against this schema.</p><p>Additionally, a validation command may be used as argument to
    the <i class="m">-validateCmd</i> option of the <i class="m">dom parse</i> and the
    <i class="m">expat</i> commands to enable validation additional to what they
    otherwise do.</p><p>The valid methods of the created commands are:</p><dl class="commandlist">
      
................................................................................
        <dt><b class="method">reset</b></dt>
        <dd>This method resets the validation command into state
        READY (while preserving the defined grammer).</dd>
      

    </dl>

  <h2><a name="SECTid0x2576900">Schema definition scripts</a></h2><p>Schema definition scripts are ordinary Tcl scripts that are
    evaluatend in the namespace tdom::schema. The below listed schema
    definition commands in this tcl namespace allow to define a wide
    variety of document structures. Every schema definition command
    establish a validation constraint on the content which has to
    match or must be optional to render the content as valid. It is a
    validation error if the element in the XML source has additional
    (not matched) content.</p><p>The schema definition commands are:</p><dl class="commandlist">
................................................................................
<b class="method">mixed</b> <i class="m">?quant?</i> <i class="m">&lt;definition script&gt;</i>
</dt>
        <dd></dd>
      

      
        <dt>
<b class="method">text</b> <i class="m">?&lt;constraint script&gt;|"type" typename?</i>
</dt>
        <dd>Without the optional constraint script this validation
        constraint matches every string (including the empty one).
        With <i class="m">constraint script</i> or with a given text type
        argument a text matching this script or the text type is
        expected. </dd>
      

      
        <dt>
<b class="method">any</b> <i class="m">?quant?</i>
</dt>
        <dd>The any command matches every element (with whatever
................................................................................
        or not. Please notice, that this mean the quantifier * and +
        will eat up any elements until the enclosing element
        ends.</dd>
      

      
        <dt>
<b class="method">attribute</b> <i class="m">name</i> <i class="m">?quant?</i> <i class="m">(?&lt;constraint script&gt;|"type" typename?)</i>
</dt>
        <dd>The attribute command defines a attribute (in no
        namespace) to the enclosing element. The first definition of
        <i class="m">name</i> inside an element definition wins; later
        definitions of the same name are silently ignored. After the
        <i class="m">name</i> argument there may be one of the qunatifieres ? or
        !. If there is, this will be used. Otherwise the attribute
        will be required (must be present in the xml source). If there
        is one argument more this argument is evaluated as constraint
        script, defining the value constrains of the attribute.
        Otherwise, if there are two more arguments and the first of
        them is the bareword "type" then the following is used as a
        text type name.</dd>
      

      
        <dt>
<b class="method">nsattribute</b> <i class="m">name</i> <i class="m">namespace</i> <i class="m">?quant?</i> <i class="m">(?&lt;constraint script&gt;|"type" typename?)</i>
</dt>
        <dd>This command does the same as the command <i class="m">attribute</i>, just for the attribute <i class="m">name</i> in the namespace <i class="m">namespace</i>.</dd>
      

      
        <dt>
<b class="method">namespace</b> <i class="m">uri</i> <i class="m">&lt;definition script&gt;</i>
</dt>
        <dd>Evaluates the <i class="m">definition script</i> with context namespace <i class="m">uri</i>. Every element or ref command name will be looked up in the namespace <i class="m">uri</i> and local defined element will be in that namespace.</dd>
      
      
      
        <dt>
<b class="method">defelement</b> <i class="m">name</i> <i class="m">?namespace?</i> <i class="m">&lt;definition script&gt;</i>
</dt>
        <dd>This defines an element type exactly as a <i>schemacmd
        defelement</i> call. This is meant as toplevel command of a
        <i>schemacmd define</i> script. This command is not allowed
        nested in an other definition script command and will raise
        error, if you call it there.</dd>
      

      
        <dt>
<b class="method">defpattern</b> <i class="m">name</i> <i class="m">?namespace?</i> <i class="m">&lt;definition script&gt;</i>
</dt>
        <dd>This defines a named pattern exactly as a <i>schemacmd
        defpattern</i> call. This is meant as toplevel command of a
        <i>schemacmd define</i> script. This command is not allowed
        nested in an other definition script command and will raise
        error, if you call it there.</dd>
      

      
        <dt>
<b class="method">start</b> <i class="m">name</i> <i class="m">?namespace?</i>
</dt>
        <dd>This command works exactly as a <i>schemacmd start</i>
        call. This is meant as toplevel command of a <i>schemacmd
        define</i> script. This command is not allowed nested in an
        other definition script command and will raise error, if you
        call it there.</dd>
      
    </dl>

  <h2><a name="SECTid0x257ec30">Quantity specifier</a></h2><p>Serveral schema definition commands expects a quantifier as
    one of their arguments, which specifies how often the content
    particle specified by the command is expected. The valid values
    for a <i class="m">quant</i> argument are:</p><dl class="optlist">
      
        <dt><b>!</b></dt>
        <dd>The content particle must occur exactly once in valid
        documents. This is the default, if a quantifier is
................................................................................
        n to m times (both inclusive) in a row in valid documents. The
        quantifier must be a tcl list with two elements. Both elements
        must be integers, with n &gt;= 0 and n &lt; m.</dd>
      
    </dl><p>If an optional quantifier is not given then it defaults to * in
    case of the mixed command and to ! for all other commands.</p>

  <h2><a name="SECTid0x2580ac0">Text constraint scripts</a></h2><p></p><p>The text constraint commands are:</p><dl class="commandlist">
      
        <dt><b class="cmd">isint</b></dt>
        <dd></dd>
      

      
        <dt>
................................................................................
        <dd></dd>
      
      
      
        <dt>
<b class="cmd">tcl</b> <i class="m">tclcmd</i> <i class="m">?arg arg ...?</i>
</dt>
        <dd>Evaluates the tcl script <i class="m">tclcmd arg arg ... </i> and
        the text to validate appended to the argument list. The return
        value of the tcl command is interpreted as a boolean.</dd>
      
      
        <dt>
<b class="cmd">enumeration</b> <i class="m">list</i>
</dt>
        <dd>This text constraint match if the text value is equal to
        one element (respecting case and any whitespace) of the
        argument <i class="m">list</i>, which has to be a valid Tcl list.
        </dd>
      
      
        <dt>
<b class="cmd">match</b> <i class="m">?-nocase?</i> <i class="m">glob style match pattern</i>
</dt>
        <dd>This text constraint match if the text value match the
        glob style pattern given as argument. It follows the rules of
        the Tcl [string match] command, see
        <a href="https://www.tcl.tk/man/tcl8.6/TclCmd/string.htm#M35">https://www.tcl.tk/man/tcl8.6/TclCmd/string.htm#M35</a>.</dd>
      
      
        <dt>
<b class="cmd">regexp</b> <i class="m">expression</i>
</dt>
        <dd>This text constraint match if the text value match the
        regular expression given as argument. <a href="https://www.tcl.tk/man/tcl8.6/TclCmd/re_syntax.htm">https://www.tcl.tk/man/tcl8.6/TclCmd/re_syntax.htm</a> describes the regular expression syntax</dd>
      
      
        <dt><b class="cmd">nmtoken</b></dt>
        <dd>This text constraint match if the text value match the
        XML nmtoken production
        <a href="https://www.w3.org/TR/xml/#NT-Nmtoken">https://www.w3.org/TR/xml/#NT-Nmtoken</a>
</dd>
      
      
        <dt><b class="cmd">nmtokens</b></dt>
        <dd>This text constraint match if the text value match the
        XML nmtokens production
        <a href="https://www.w3.org/TR/xml/#NT-Nmtokens">https://www.w3.org/TR/xml/#NT-Nmtokens</a>
</dd>
      
      
        <dt><b class="cmd">number</b></dt>
        <dd></dd>
      
      
        <dt><b class="cmd">boolean</b></dt>
        <dd></dd>
      
      
        <dt><b class="cmd">isodate</b></dt>
        <dd></dd>
      
      
        <dt>
<b class="cmd">maxLength</b> <i class="m">length</i>
</dt>
        <dd>This text constraint match if the length of the text
        value (in characters, not bytes) is at most <i class="m">length</i>. The
        length argument must be an integer greater zero.</dd>
      
      
        <dt>
<b class="cmd">minLength</b> <i class="m">length</i>
</dt>
        <dd>This text constraint match if the length of the text
        value (in characters, not bytes) is at least <i class="m">length</i>.
        The length argument must be an integer greater zero.</dd>
      
      
        <dt>
<b class="cmd">oneOf</b> <i class="m">&lt;constraint script&gt;</i>
</dt>
        <dd>This text constraint match if one of the text
        constraints defined in the argument <i class="m">constraint script</i>
        match the text. It stops after the first match and probes the
        text constraints in the order of definition.</dd>
      
      
        <dt>
<b class="cmd">allOf</b> <i class="m">&lt;constraint script&gt;</i>
</dt>
        <dd>This text constraint match if all of the text
        constraints defined in the argument <i class="m">constraint script</i>
        match the text. It stops after the first match failues and
        probes the text constraints in the order of definition. Since
        the schema definition commmand <i class="m">text</i> also expects all
        text constraints to match the text constraint <i class="m">allOf</i> is
        useful mostly together with the <i class="m">oneOf</i> text constraint
        commmand.</dd>
      
    </dl>
  
  <h2><a name="SECTid0x2586740">Exampels</a></h2><p>The XML Schema Part 0: Primer Second Edition
    (<a href="https://www.w3.org/TR/xmlschema-0/">https://www.w3.org/TR/xmlschema-0/</a>) starts with this
    example schema:</p><pre class="example">
&lt;xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;

  &lt;xsd:annotation&gt;
    &lt;xsd:documentation xml:lang="en"&gt;
     Purchase order schema for Example.com.
................................................................................
            attribute partNum ! {text {pattern "\d{3}-[A-Z]{2}"}}
        }
    }
}
      
    </pre><p>The RELAX NG Tutorial
    (<a href="http://relaxng.org/tutorial-20011203.html">http://relaxng.org/tutorial-20011203.html</a>) starts with
described at     this example:</p><pre class="example">
Consider a simple XML representation of an email address book:

&lt;addressBook&gt;
  &lt;card&gt;
    &lt;name&gt;John Smith&lt;/name&gt;
    &lt;email&gt;[email protected]&lt;/email&gt;
  &lt;/card&gt;

Changes to doc/schema.n.

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
...
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
...
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
.TP
\&\fB\fBinterleave\fP \fI?quant?\fB \fI<definition script>\fB
\&\fR
.TP
\&\fB\fBmixed\fP \fI?quant?\fB \fI<definition script>\fB
\&\fR
.TP
\&\fB\fBtext\fP \fI?<constraint script>?\fB
\&\fRWithout the optional constraint script this validation
constraint matches every string (including the empty one).
With \fIconstraint script\fR argument a text matching this

script is expected.
.TP
\&\fB\fBany\fP \fI?quant?\fB
\&\fRThe any command matches every element (with whatever
attributes) or subtree, no matter if known within the schema
or not. Please notice, that this mean the quantifier * and +
will eat up any elements until the enclosing element
ends.
.TP
\&\fB\fBattribute\fP \fIname\fB \fI?quant?\fB \fI?<constraint script>?\fB
\&\fR











.TP
\&\fB\fBnsattribute\fP \fIname\fB \fInamespace\fB \fI?quant?\fB \fI?<constraint script>?\fB
\&\fR

.TP
\&\fB\fBnamespace\fP \fIuri\fB \fI<definition script>\fB
\&\fREvaluates the \fIdefinition script\fR with context namespace \fIuri\fR.
.TP
\&\fB\fBdefelement\fP \fIname\fB \fI?namespace?\fB \fI<definition script>\fB



\&\fRThis command is not allowed nested in an other definition script command.

.TP
\&\fB\fBdefpattern\fP \fIname\fB \fI?namespace?\fB \fI<definition script>\fB



\&\fRThis command is not allowed nested in an other definition script command.

.TP
\&\fB\fBstart\fP \fIname\fB \fI?namespace?\fB


\&\fRThis command is not allowed nested in an other definition script command.


.SH "Quantity specifier"
.PP
Serveral schema definition commands expects a quantifier as
one of their arguments, which specifies how often the content
particle specified by the command is expected. The valid values
for a \fIquant\fR argument are:
.IP "\fB!\fR"
................................................................................
\&\fB\fBisint\fP
\&\fR
.TP
\&\fB\fBfixed\fP \fIvalue\fB
\&\fR
.TP
\&\fB\fBtcl\fP \fItclcmd\fB \fI?arg arg ...?\fB
\&\fR


.TP
\&\fB\fBenumeration\fP \fIlist\fB
\&\fR



.TP
\&\fB\fBmatch\fP \fIglob style match pattern\fB






\&\fR
.TP







\&\fB\fBnmtoken\fP














\&\fR
.TP
\&\fB\fBnmtokens\fP
\&\fR





























.SH Exampels
.PP
.UR "https://www.w3.org/TR/xmlschema-0/"
<URL: https://www.w3.org/TR/xmlschema-0/>
.UE
The XML Schema Part 0: Primer Second Edition
() starts with this
................................................................................
.CE
.PP
.UR "http://relaxng.org/tutorial-20011203.html"
<URL: http://relaxng.org/tutorial-20011203.html>
.UE
The RELAX NG Tutorial
() starts with
this example:
.CS

Consider a simple XML representation of an email address book:

<addressBook>
  <card>
    <name>John Smith</name>






|


|
>
|








|
|
>
>
>
>
>
>
>
>
>
>
>

|
<
>


|


>
>
>
|
>


>
>
>
|
>


>
>
|
>
>







 







|
>
>


<
>
>
>

|
>
>
>
>
>
>
|

>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>


|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







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
...
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
...
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
.TP
\&\fB\fBinterleave\fP \fI?quant?\fB \fI<definition script>\fB
\&\fR
.TP
\&\fB\fBmixed\fP \fI?quant?\fB \fI<definition script>\fB
\&\fR
.TP
\&\fB\fBtext\fP \fI?<constraint script>|\*(lqtype\*(lq typename?\fB
\&\fRWithout the optional constraint script this validation
constraint matches every string (including the empty one).
With \fIconstraint script\fR or with a given text type
argument a text matching this script or the text type is
expected.
.TP
\&\fB\fBany\fP \fI?quant?\fB
\&\fRThe any command matches every element (with whatever
attributes) or subtree, no matter if known within the schema
or not. Please notice, that this mean the quantifier * and +
will eat up any elements until the enclosing element
ends.
.TP
\&\fB\fBattribute\fP \fIname\fB \fI?quant?\fB \fI(?<constraint script>|\*(lqtype\*(lq typename?)\fB
\&\fRThe attribute command defines a attribute (in no
namespace) to the enclosing element. The first definition of
\&\fIname\fR inside an element definition wins; later
definitions of the same name are silently ignored. After the
\&\fIname\fR argument there may be one of the qunatifieres ? or
!. If there is, this will be used. Otherwise the attribute
will be required (must be present in the xml source). If there
is one argument more this argument is evaluated as constraint
script, defining the value constrains of the attribute.
Otherwise, if there are two more arguments and the first of
them is the bareword "type" then the following is used as a
text type name.
.TP
\&\fB\fBnsattribute\fP \fIname\fB \fInamespace\fB \fI?quant?\fB \fI(?<constraint script>|\*(lqtype\*(lq typename?)\fB

\&\fRThis command does the same as the command \fIattribute\fR, just for the attribute \fIname\fR in the namespace \fInamespace\fR.
.TP
\&\fB\fBnamespace\fP \fIuri\fB \fI<definition script>\fB
\&\fREvaluates the \fIdefinition script\fR with context namespace \fIuri\fR. Every element or ref command name will be looked up in the namespace \fIuri\fR and local defined element will be in that namespace.
.TP
\&\fB\fBdefelement\fP \fIname\fB \fI?namespace?\fB \fI<definition script>\fB
\&\fRThis defines an element type exactly as a \fIschemacmd
defelement\fR call. This is meant as toplevel command of a
\&\fIschemacmd define\fR script. This command is not allowed
nested in an other definition script command and will raise
error, if you call it there.
.TP
\&\fB\fBdefpattern\fP \fIname\fB \fI?namespace?\fB \fI<definition script>\fB
\&\fRThis defines a named pattern exactly as a \fIschemacmd
defpattern\fR call. This is meant as toplevel command of a
\&\fIschemacmd define\fR script. This command is not allowed
nested in an other definition script command and will raise
error, if you call it there.
.TP
\&\fB\fBstart\fP \fIname\fB \fI?namespace?\fB
\&\fRThis command works exactly as a \fIschemacmd start\fR
call. This is meant as toplevel command of a \fIschemacmd
define\fR script. This command is not allowed nested in an
other definition script command and will raise error, if you
call it there.
.SH "Quantity specifier"
.PP
Serveral schema definition commands expects a quantifier as
one of their arguments, which specifies how often the content
particle specified by the command is expected. The valid values
for a \fIquant\fR argument are:
.IP "\fB!\fR"
................................................................................
\&\fB\fBisint\fP
\&\fR
.TP
\&\fB\fBfixed\fP \fIvalue\fB
\&\fR
.TP
\&\fB\fBtcl\fP \fItclcmd\fB \fI?arg arg ...?\fB
\&\fREvaluates the tcl script \fItclcmd arg arg ... \fR and
the text to validate appended to the argument list. The return
value of the tcl command is interpreted as a boolean.
.TP
\&\fB\fBenumeration\fP \fIlist\fB

\&\fRThis text constraint match if the text value is equal to
one element (respecting case and any whitespace) of the
argument \fIlist\fR, which has to be a valid Tcl list.
.TP
\&\fB\fBmatch\fP \fI?-nocase?\fB \fIglob style match pattern\fB
.UR "https://www.tcl.tk/man/tcl8.6/TclCmd/string.htm#M35"
<URL: https://www.tcl.tk/man/tcl8.6/TclCmd/string.htm#M35>
.UE
\&\fRThis text constraint match if the text value match the
glob style pattern given as argument. It follows the rules of
the Tcl [string match] command, see
\&.
.TP
\&\fB\fBregexp\fP \fIexpression\fB
.UR "https://www.tcl.tk/man/tcl8.6/TclCmd/re_syntax.htm"
<URL: https://www.tcl.tk/man/tcl8.6/TclCmd/re_syntax.htm>
.UE
\&\fRThis text constraint match if the text value match the
regular expression given as argument.  describes the regular expression syntax
.TP
\&\fB\fBnmtoken\fP
.UR "https://www.w3.org/TR/xml/#NT-Nmtoken"
<URL: https://www.w3.org/TR/xml/#NT-Nmtoken>
.UE
\&\fRThis text constraint match if the text value match the
XML nmtoken production
.TP
\&\fB\fBnmtokens\fP
.UR "https://www.w3.org/TR/xml/#NT-Nmtokens"
<URL: https://www.w3.org/TR/xml/#NT-Nmtokens>
.UE
\&\fRThis text constraint match if the text value match the
XML nmtokens production
.TP
\&\fB\fBnumber\fP
\&\fR
.TP
\&\fB\fBboolean\fP
\&\fR
.TP
\&\fB\fBisodate\fP
\&\fR
.TP
\&\fB\fBmaxLength\fP \fIlength\fB
\&\fRThis text constraint match if the length of the text
value (in characters, not bytes) is at most \fIlength\fR. The
length argument must be an integer greater zero.
.TP
\&\fB\fBminLength\fP \fIlength\fB
\&\fRThis text constraint match if the length of the text
value (in characters, not bytes) is at least \fIlength\fR.
The length argument must be an integer greater zero.
.TP
\&\fB\fBoneOf\fP \fI<constraint script>\fB
\&\fRThis text constraint match if one of the text
constraints defined in the argument \fIconstraint script\fR
match the text. It stops after the first match and probes the
text constraints in the order of definition.
.TP
\&\fB\fBallOf\fP \fI<constraint script>\fB
\&\fRThis text constraint match if all of the text
constraints defined in the argument \fIconstraint script\fR
match the text. It stops after the first match failues and
probes the text constraints in the order of definition. Since
the schema definition commmand \fItext\fR also expects all
text constraints to match the text constraint \fIallOf\fR is
useful mostly together with the \fIoneOf\fR text constraint
commmand.
.SH Exampels
.PP
.UR "https://www.w3.org/TR/xmlschema-0/"
<URL: https://www.w3.org/TR/xmlschema-0/>
.UE
The XML Schema Part 0: Primer Second Edition
() starts with this
................................................................................
.CE
.PP
.UR "http://relaxng.org/tutorial-20011203.html"
<URL: http://relaxng.org/tutorial-20011203.html>
.UE
The RELAX NG Tutorial
() starts with
described at     this example:
.CS

Consider a simple XML representation of an email address book:

<addressBook>
  <card>
    <name>John Smith</name>

Changes to doc/schema.xml.

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
...
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
...
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
      <commanddef>
        <command><method>mixed</method> <m>?quant?</m> <m>&lt;definition script></m></command>
        <desc></desc>
      </commanddef>

      <commanddef>
        <command><method>text</method> <m>?&lt;constraint script>?</m></command>
        <desc>Without the optional constraint script this validation
        constraint matches every string (including the empty one). If
        the <m>constraint script</m> argument is given then a text
        machtes if it passes all text constraints in the
        script.</desc>
      </commanddef>

      <commanddef>
        <command><method>any</method> <m>?quant?</m></command>
        <desc>The any command matches every element (with whatever
        attributes) or subtree, no matter if known within the schema
        or not. Please notice, that this mean the quantifier * and +
        will eat up any elements until the enclosing element
        ends.</desc>
      </commanddef>

      <commanddef>
        <command><method>attribute</method> <m>name</m> <m>?quant?</m> <m>?&lt;constraint script>?</m></command>











        <desc></desc>
      </commanddef>

      <commanddef>
        <command><method>nsattribute</method> <m>name</m> <m>namespace</m> <m>?quant?</m> <m>?&lt;constraint script>?</m></command>
        <desc></desc>
      </commanddef>

      <commanddef>
        <command><method>namespace</method> <m>uri</m> <m>&lt;definition script></m></command>
        <desc>Evaluates the <m>definition script</m> with context namespace <m>uri</m>.</desc>
      </commanddef>
      
      <commanddef>
        <command><method>defelement</method> <m>name</m> <m>?namespace?</m> <m>&lt;definition script></m></command>



        <desc>This command is not allowed nested in an other definition script command.</desc>

      </commanddef>

      <commanddef>
        <command><method>defpattern</method> <m>name</m> <m>?namespace?</m> <m>&lt;definition script></m></command>



        <desc>This command is not allowed nested in an other definition script command.</desc>

      </commanddef>

      <commanddef>
        <command><method>start</method> <m>name</m> <m>?namespace?</m></command>


        <desc>This command is not allowed nested in an other definition script command.</desc>


      </commanddef>
    </commandlist>
    
  </section>

  <section>
    <title>Quantity specifier</title>
................................................................................
        <command><cmd>tcl</cmd> <m>tclcmd</m> <m>?arg arg ...?</m></command>
        <desc>Evaluates the tcl script <m>tclcmd arg arg ... </m> and
        the text to validate appended to the argument list. The return
        value of the tcl command is interpreted as a boolean.</desc>
      </commanddef>
      <commanddef>
        <command><cmd>enumeration</cmd> <m>list</m></command>



        <desc></desc>
      </commanddef>
      <commanddef>
        <command><cmd>match</cmd> <m>glob style match pattern</m></command>
        <desc></desc>









      </commanddef>
      <commanddef>
        <command><cmd>nmtoken</cmd></command>
        <desc></desc>


      </commanddef>
      <commanddef>
        <command><cmd>nmtokens</cmd></command>
        <desc></desc>


      </commanddef>
      <commanddef>
        <command><cmd>number</cmd></command>
        <desc></desc>
      </commanddef>
      <commanddef>
        <command><cmd>boolean</cmd></command>
................................................................................
        <desc></desc>
      </commanddef>
      <commanddef>
        <command><cmd>isodate</cmd></command>
        <desc></desc>
      </commanddef>
      <commanddef>
        <command><cmd>maxLength</cmd></command>
        <desc></desc>


      </commanddef>
      <commanddef>
        <command><cmd>minLength</cmd></command>
        <desc></desc>



      </commanddef>
      <commanddef>
        <command><cmd>oneOf</cmd> <m>&lt;constraint script></m></command>
        <desc>This text constraint match if one of the text
        constraints defined in the argument <m>constraint script</m>
        match the text. It stops after the first match and probes the
        text constraints in the order of definition.</desc>
................................................................................
    }
}
      
    </example>

    <p>The RELAX NG Tutorial
    (<url>http://relaxng.org/tutorial-20011203.html</url>) starts with
    this example:</p>

    <example>
Consider a simple XML representation of an email address book:

&lt;addressBook>
  &lt;card>
    &lt;name>John Smith&lt;/name>






|

|
|
|
|












|
>
>
>
>
>
>
>
>
>
>
>
|



|
|




|




>
>
>
|
>




>
>
>
|
>




>
>
|
>
>







 







>
>
>
|


|
<
>
>
>
>
>
>
>
>
>



|
>
>



|
>
>







 







|
|
>
>


|
<
>
>
>







 







|







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
...
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
...
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
      <commanddef>
        <command><method>mixed</method> <m>?quant?</m> <m>&lt;definition script></m></command>
        <desc></desc>
      </commanddef>

      <commanddef>
        <command><method>text</method> <m>?&lt;constraint script>|"type" typename?</m></command>
        <desc>Without the optional constraint script this validation
        constraint matches every string (including the empty one).
        With <m>constraint script</m> or with a given text type
        argument a text matching this script or the text type is
        expected. </desc>
      </commanddef>

      <commanddef>
        <command><method>any</method> <m>?quant?</m></command>
        <desc>The any command matches every element (with whatever
        attributes) or subtree, no matter if known within the schema
        or not. Please notice, that this mean the quantifier * and +
        will eat up any elements until the enclosing element
        ends.</desc>
      </commanddef>

      <commanddef>
        <command><method>attribute</method> <m>name</m> <m>?quant?</m> <m>(?&lt;constraint script>|"type" typename?)</m></command>
        <desc>The attribute command defines a attribute (in no
        namespace) to the enclosing element. The first definition of
        <m>name</m> inside an element definition wins; later
        definitions of the same name are silently ignored. After the
        <m>name</m> argument there may be one of the qunatifieres ? or
        !. If there is, this will be used. Otherwise the attribute
        will be required (must be present in the xml source). If there
        is one argument more this argument is evaluated as constraint
        script, defining the value constrains of the attribute.
        Otherwise, if there are two more arguments and the first of
        them is the bareword "type" then the following is used as a
        text type name.</desc>
      </commanddef>

      <commanddef>
        <command><method>nsattribute</method> <m>name</m> <m>namespace</m> <m>?quant?</m> <m>(?&lt;constraint script>|"type" typename?)</m></command>
        <desc>This command does the same as the command <m>attribute</m>, just for the attribute <m>name</m> in the namespace <m>namespace</m>.</desc>
      </commanddef>

      <commanddef>
        <command><method>namespace</method> <m>uri</m> <m>&lt;definition script></m></command>
        <desc>Evaluates the <m>definition script</m> with context namespace <m>uri</m>. Every element or ref command name will be looked up in the namespace <m>uri</m> and local defined element will be in that namespace.</desc>
      </commanddef>
      
      <commanddef>
        <command><method>defelement</method> <m>name</m> <m>?namespace?</m> <m>&lt;definition script></m></command>
        <desc>This defines an element type exactly as a <i>schemacmd
        defelement</i> call. This is meant as toplevel command of a
        <i>schemacmd define</i> script. This command is not allowed
        nested in an other definition script command and will raise
        error, if you call it there.</desc>
      </commanddef>

      <commanddef>
        <command><method>defpattern</method> <m>name</m> <m>?namespace?</m> <m>&lt;definition script></m></command>
        <desc>This defines a named pattern exactly as a <i>schemacmd
        defpattern</i> call. This is meant as toplevel command of a
        <i>schemacmd define</i> script. This command is not allowed
        nested in an other definition script command and will raise
        error, if you call it there.</desc>
      </commanddef>

      <commanddef>
        <command><method>start</method> <m>name</m> <m>?namespace?</m></command>
        <desc>This command works exactly as a <i>schemacmd start</i>
        call. This is meant as toplevel command of a <i>schemacmd
        define</i> script. This command is not allowed nested in an
        other definition script command and will raise error, if you
        call it there.</desc>
      </commanddef>
    </commandlist>
    
  </section>

  <section>
    <title>Quantity specifier</title>
................................................................................
        <command><cmd>tcl</cmd> <m>tclcmd</m> <m>?arg arg ...?</m></command>
        <desc>Evaluates the tcl script <m>tclcmd arg arg ... </m> and
        the text to validate appended to the argument list. The return
        value of the tcl command is interpreted as a boolean.</desc>
      </commanddef>
      <commanddef>
        <command><cmd>enumeration</cmd> <m>list</m></command>
        <desc>This text constraint match if the text value is equal to
        one element (respecting case and any whitespace) of the
        argument <m>list</m>, which has to be a valid Tcl list.
        </desc>
      </commanddef>
      <commanddef>
        <command><cmd>match</cmd> <m>?-nocase?</m> <m>glob style match pattern</m></command>

        <desc>This text constraint match if the text value match the
        glob style pattern given as argument. It follows the rules of
        the Tcl [string match] command, see
        <url>https://www.tcl.tk/man/tcl8.6/TclCmd/string.htm#M35</url>.</desc>
      </commanddef>
      <commanddef>
        <command><cmd>regexp</cmd> <m>expression</m></command>
        <desc>This text constraint match if the text value match the
        regular expression given as argument. <url>https://www.tcl.tk/man/tcl8.6/TclCmd/re_syntax.htm</url> describes the regular expression syntax</desc>
      </commanddef>
      <commanddef>
        <command><cmd>nmtoken</cmd></command>
        <desc>This text constraint match if the text value match the
        XML nmtoken production
        <url>https://www.w3.org/TR/xml/#NT-Nmtoken</url></desc>
      </commanddef>
      <commanddef>
        <command><cmd>nmtokens</cmd></command>
        <desc>This text constraint match if the text value match the
        XML nmtokens production
        <url>https://www.w3.org/TR/xml/#NT-Nmtokens</url></desc>
      </commanddef>
      <commanddef>
        <command><cmd>number</cmd></command>
        <desc></desc>
      </commanddef>
      <commanddef>
        <command><cmd>boolean</cmd></command>
................................................................................
        <desc></desc>
      </commanddef>
      <commanddef>
        <command><cmd>isodate</cmd></command>
        <desc></desc>
      </commanddef>
      <commanddef>
        <command><cmd>maxLength</cmd> <m>length</m></command>
        <desc>This text constraint match if the length of the text
        value (in characters, not bytes) is at most <m>length</m>. The
        length argument must be an integer greater zero.</desc>
      </commanddef>
      <commanddef>
        <command><cmd>minLength</cmd> <m>length</m></command>

        <desc>This text constraint match if the length of the text
        value (in characters, not bytes) is at least <m>length</m>.
        The length argument must be an integer greater zero.</desc>
      </commanddef>
      <commanddef>
        <command><cmd>oneOf</cmd> <m>&lt;constraint script></m></command>
        <desc>This text constraint match if one of the text
        constraints defined in the argument <m>constraint script</m>
        match the text. It stops after the first match and probes the
        text constraints in the order of definition.</desc>
................................................................................
    }
}
      
    </example>

    <p>The RELAX NG Tutorial
    (<url>http://relaxng.org/tutorial-20011203.html</url>) starts with
described at     this example:</p>

    <example>
Consider a simple XML representation of an email address book:

&lt;addressBook>
  &lt;card>
    &lt;name>John Smith&lt;/name>

Changes to generic/schema.c.

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
...
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
...
165
166
167
168
169
170
171















172
173
174
175
176
177
178
...
194
195
196
197
198
199
200










































201
202
203
204
205
206
207
...
348
349
350
351
352
353
354
355

356
357
358

359
360
361



362
363
364
365
366
367
368
...
398
399
400
401
402
403
404









405
406
407
408
409
410
411
...
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
...
719
720
721
722
723
724
725

726
727
728
729
730
731
732
...
736
737
738
739
740
741
742




















743
744
745
746
747
748
749
....
1941
1942
1943
1944
1945
1946
1947

1948
1949
1950
1951

1952
1953
1954
1955
1956
1957
1958



























































































1959
1960
1961
1962
1963
1964
1965
....
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984

1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
....
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
....
2020
2021
2022
2023
2024
2025
2026

2027
2028
2029
2030
2031
2032
2033
....
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102

2103
2104

2105
2106
2107
2108
2109
2110
2111
....
2121
2122
2123
2124
2125
2126
2127

2128
2129
2130
2131

2132
2133
2134
2135

2136
2137
2138
2139
2140
2141
2142
2143

2144
2145

2146
2147
2148
2149
2150
2151
2152
2153

2154
2155
2156
2157
2158
2159
2160
....
2178
2179
2180
2181
2182
2183
2184

2185
2186
2187
2188
2189
2190
2191
....
2204
2205
2206
2207
2208
2209
2210

2211
2212
2213
2214
2215
2216
2217
....
2259
2260
2261
2262
2263
2264
2265
2266


2267
2268
2269
2270
2271
2272
2273
....
2287
2288
2289
2290
2291
2292
2293

2294
2295
2296
2297

2298
2299
2300
2301
2302
2303
2304
....
2312
2313
2314
2315
2316
2317
2318

2319
2320
2321
2322
2323
2324
2325
....
2344
2345
2346
2347
2348
2349
2350


















2351
2352
2353
2354
2355



2356
2357
2358
2359
2360
2361
2362
....
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
....
2568
2569
2570
2571
2572
2573
2574

2575

2576
2577
2578
2579
2580
2581
2582
....
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
....
2733
2734
2735
2736
2737
2738
2739
2740

2741
2742
2743
2744
2745
2746
2747
....
2775
2776
2777
2778
2779
2780
2781


2782
2783
2784
2785
2786
2787
2788
....
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814


2815
2816
2817
2818
2819

2820
2821
2822
2823
2824
2825
2826
2827

2828
2829
2830
2831
2832
2833




2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850












2851
2852
2853





2854
2855
2856




2857

2858
2859




2860
2861
2862
2863
2864
2865
2866
....
2881
2882
2883
2884
2885
2886
2887

2888

2889
2890
2891
2892
2893
2894
2895
....
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
....
3007
3008
3009
3010
3011
3012
3013

3014
3015
3016
3017
3018
3019
3020
....
3036
3037
3038
3039
3040
3041
3042

3043
3044

3045
3046
3047
3048
3049
3050
3051
....
3081
3082
3083
3084
3085
3086
3087

3088
3089
3090
3091
3092
3093
3094
....
3200
3201
3202
3203
3204
3205
3206












3207

3208
3209
3210
3211
3212
3213
3214
....
3218
3219
3220
3221
3222
3223
3224



3225




3226

3227



3228
3229
3230
3231
3232
3233
3234
....
3488
3489
3490
3491
3492
3493
3494

3495
3496
3497
3498
3499
3500
3501
....
3746
3747
3748
3749
3750
3751
3752


3753
3754
3755
3756
3757
3758
3759
|   License for the specific language governing rights and limitations
|   under the License.
|
|   Contributor(s):
|
|
|   written by Rolf Ade
|   Nov, Dec, Jan 2018-2019
|
\---------------------------------------------------------------------------*/

#ifndef TDOM_NO_SCHEMA

#include <tdom.h>
#include <tcldom.h>
................................................................................
    SchemaData **schemaInfoPtr = Tcl_GetThreadData(&activeSchemaData,
                                                        sizeof (SchemaData*));
    *schemaInfoPtr = v;
}
# define SETASI(v) SetActiveSchemaData (v)
#endif


#define CHECK_SI                                                        \
    if (!sdata) {                                                       \
        SetResult ("Command called outside of schema context");         \
        return TCL_ERROR;                                               \
    }                                                                   \
    if (sdata->isTextConstraint) {                                      \
        SetResult ("Command called in invalid schema context");         \
................................................................................
#define CHECK_TOPLEVEL                                                  \
    if (sdata->defineToplevel) {                                        \
        SetResult("Command not allowed at top level "                   \
                  "in schema define evaluation");                       \
        return TCL_ERROR;                                               \
    }
















#define REMEMBER_PATTERN(pattern)                                       \
    if (sdata->numPatternList == sdata->patternListSize) {              \
        sdata->patternList = (SchemaCP **) REALLOC (                    \
            sdata->patternList,                                         \
            sizeof (SchemaCP*) * sdata->patternListSize * 2);           \
        sdata->patternListSize *= 2;                                    \
    }                                                                   \
................................................................................
                     * sizeof (SchemaQuant));                           \
        sdata->contentSize *= 2;                                        \
    }                                                                   \
    sdata->cp->content[sdata->cp->nc] = (SchemaCP *) sc;                \
    sdata->cp->quants[sdata->cp->nc] = SCHEMA_CQUANT_ONE;               \
    sdata->cp->nc++;                                                    \











































static SchemaCP*
initSchemaCP (
    Schema_CP_Type type,
    void *namespace,
    char *name
    )
{
................................................................................
        }
        break;
    }
    FREE (pattern);
}

static SchemaData*
initSchemaData ()

{
    SchemaData *sdata;
    int hnew;


    sdata = TMALLOC (SchemaData);
    memset (sdata, 0, sizeof(SchemaData));



    Tcl_InitHashTable (&sdata->element, TCL_STRING_KEYS);
    Tcl_InitHashTable (&sdata->pattern, TCL_STRING_KEYS);
    Tcl_InitHashTable (&sdata->attrNames, TCL_STRING_KEYS);
    Tcl_InitHashTable (&sdata->namespace, TCL_STRING_KEYS);
    Tcl_InitHashTable (&sdata->textDef, TCL_STRING_KEYS);
    sdata->emptyNamespace = Tcl_CreateHashEntry (
        &sdata->namespace, "", &hnew);
................................................................................
    ClientData clientData
    )
{
    SchemaData *sdata = (SchemaData *) clientData;
    unsigned int i;
    SchemaValidationStack *down;










    if (sdata->start) FREE (sdata->start);
    if (sdata->startNamespace) FREE (sdata->startNamespace);
    Tcl_DeleteHashTable (&sdata->namespace);
    Tcl_DeleteHashTable (&sdata->element);
    Tcl_DeleteHashTable (&sdata->pattern);
    Tcl_DeleteHashTable (&sdata->attrNames);
    Tcl_DeleteHashTable (&sdata->textDef);
................................................................................
    if (pattern->type == SCHEMA_CTYPE_INTERLEAVE) {
        stackElm->interleaveState = MALLOC (sizeof (int) * pattern->nc);
        memset (stackElm->interleaveState, 0, sizeof (int) * pattern->nc);
    }
    sdata->stack = stackElm;
}

#define maxOne(quant) \
    ((quant) == SCHEMA_CQUANT_ONE || (quant) == SCHEMA_CQUANT_OPT) ? 1 : 0

#define minOne(quant) \
    ((quant) == SCHEMA_CQUANT_ONE || (quant) == SCHEMA_CQUANT_PLUS) ? 1 : 0

#define mayRepeat(quant) \
    ((quant) == SCHEMA_CQUANT_REP || (quant) == SCHEMA_CQUANT_PLUS) ? 1 : 0

#define mayMiss(quant) \
    ((quant) == SCHEMA_CQUANT_REP || (quant) == SCHEMA_CQUANT_OPT) ? 1 : 0

#define hasMatched(quant,hm) \
    (hm) == 0 ?  mayMiss(quant) :  1

#define mustMatch(quant,hm) \
    (hm) == 0 ? minOne(quant) : 0


#define getContext(cp, ac, hm)        \
    cp = se->pattern;                 \
    ac = se->activeChild;             \
    hm = se->hasMatched;


#define updateStack(se,cp,ac)                     \
    if (maxOne (cp->quants[ac])) {                \
        se->activeChild = ac + 1;                 \
        se->hasMatched = 0;                       \
    } else {                                      \
        se->activeChild = ac;                     \
        se->hasMatched = 1;                       \
    }

static void
popStack (
    SchemaData *sdata
    )
{
    SchemaValidationStack *se;
    DBG(fprintf(stderr, "pop from Stack:\n");serializeCP(sdata->stack->pattern));
................................................................................
    char *namespace
    )
{
    SchemaCP *cp, *candidate, *icp;
    int hm, ac, i, mayskip, rc;
    int isName = 0;
    SchemaValidationStack *se;


    if (!sdata->stack) return 0;
    se = sdata->stack;
    getContext (cp, ac, hm);

    switch (cp->type) {
    case SCHEMA_CTYPE_NAME:
................................................................................
        while (ac < cp->nc) {
            candidate = cp->content[ac];
            mayskip = 0;
            switch (candidate->type) {
            case SCHEMA_CTYPE_TEXT:
                if (candidate->nc) {
                    if (!checkText (interp, candidate, "")) {




















                        return 0;
                    }
                }
                break;

            case SCHEMA_CTYPE_ANY:
                updateStack (se, cp, ac);
................................................................................
    savedContenSize = sdata->contentSize;
    savedIsTextConstraint = sdata->isTextConstraint;
    /* ... and prepare sdata for definition evaluation. */
    sdata->cp = cp;
    sdata->contentSize = CONTENT_ARRAY_SIZE_INIT;
    sdata->isTextConstraint = 1;
    sdata->textStub[3] = script;

    result = Tcl_EvalObjv (interp, 4, sdata->textStub,
                           TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL);
    sdata->isTextConstraint = savedIsTextConstraint;
    /* ... and restore the previously saved sdata states  */

    sdata->cp = savedCP;
    sdata->contentSize = savedContenSize;
    if (sdata->cp && !sdata->isAttributeConstaint && cp->nc) {
        sdata->cp->flags |= CONSTRAINT_TEXT_CHILD;
    }
    return result;
}




























































































int
schemaInstanceCmd (
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[]
................................................................................
    SchemaCP      *pattern, *current = NULL;
    void          *namespacePtr, *savedNamespacePtr;
    char          *xmlstr, *errMsg;
    domDocument   *doc;
    domNode       *node;

    static const char *schemaInstanceMethods[] = {
        "defelement", "defpattern",  "start", "event", "delete",
        "nrForwardDefinitions",      "state", "reset", "define",
        "validate",   "domvalidate", "deftext", NULL

    };
    enum schemaInstanceMethod {
        m_defelement,  m_defpattern,  m_start, m_event, m_delete,
        m_nrForwardDefinitions,       m_state, m_reset, m_define,
        m_validate,    m_domvalidate, m_deftext
    };

    static const char *eventKeywords[] = {
        "start", "end", "text", NULL
    };

    enum eventKeyword
................................................................................

    if (objc < 2) {
        Tcl_WrongNumArgs (interp, 1, objv, "subcommand ?arguments?");
        return TCL_ERROR;
    }

    if (sdata == NULL) {
        /* Inline defined defelement, defpattern or start */
        sdata = GETASI;
        CHECK_SI;
        if (!sdata->defineToplevel) {
            SetResult ("Command not allowed in nested schema define script");
            return TCL_ERROR;
        }
        i = 1;
    }

    if (Tcl_GetIndexFromObj (interp, objv[1-i], schemaInstanceMethods,
                             "method", 0, &methodIndex)
................................................................................
        return TCL_ERROR;
    }

    Tcl_ResetResult (interp);
    switch ((enum schemaInstanceMethod) methodIndex) {
    case m_defelement:
    case m_defpattern:

        if (objc != 4-i && objc != 5-i) {
            Tcl_WrongNumArgs (interp, 1-i, objv, "<name>"
                 " ?<namespace>? pattern");
            return TCL_ERROR;
        }
        if ((enum schemaInstanceMethod) methodIndex == m_defelement) {
            hashTable = &sdata->element;
................................................................................
                current = (SchemaCP *) Tcl_GetHashValue (h);
                pattern->next = current;
            }
            REMEMBER_PATTERN (pattern);
            Tcl_SetHashValue (h, pattern);
        }

        if (!sdata->defineToplevel) {
            savedsdata = GETASI;
            if (savedsdata == sdata) {
                SetResult ("Recursive call of schema command is not allowed");
                return TCL_ERROR;
            }
            SETASI(sdata);
        }
        savedDefineToplevel = sdata->defineToplevel;
        savedNamespacePtr = sdata->currentNamespace;
        sdata->defineToplevel = 0;
        sdata->currentNamespace = namespacePtr;
        sdata->cp = pattern;
        sdata->numAttr = 0;
        sdata->numReqAttr = 0;
        sdata->currentAttrs = NULL;
        sdata->contentSize = CONTENT_ARRAY_SIZE_INIT;
        sdata->evalStub[3] = objv[patternIndex];

        result = Tcl_EvalObjv (interp, 4, sdata->evalStub,
                               TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL);

        sdata->currentNamespace = NULL;
        pattern->attrs = sdata->currentAttrs;
        pattern->numAttr = sdata->numAttr;
        pattern->numReqAttr = sdata->numReqAttr;
        if (result == TCL_OK) {
            if (forwardDef) {
                if (pattern->flags & FORWARD_PATTERN_DEF) {
................................................................................
        sdata->currentNamespace = savedNamespacePtr;
        if (!savedDefineToplevel) {
            SETASI(savedsdata);
        }
        break;

    case m_define:

        if (objc != 3) {
            Tcl_WrongNumArgs (interp, 2, objv, "<definition commands>");
            return TCL_ERROR;
        }

        savedsdata = GETASI;
        if (savedsdata == sdata) {
            SetResult ("Recursive call of schema command is not allowed");
            return TCL_ERROR;

        }
        SETASI(sdata);
        savedNumPatternList = sdata->numPatternList;
        sdata->currentNamespace = 0;
        sdata->cp = NULL;
        sdata->contentSize = 0;
        sdata->defineToplevel = 1;
        sdata->evalStub[3] = objv[2];

        result = Tcl_EvalObjv (interp, 4, sdata->evalStub,
                               TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL);

        if (result != TCL_OK) {
            cleanupLastPattern (sdata, savedNumPatternList);
        }
        sdata->defineToplevel = 0;
        SETASI(savedsdata);
        break;

    case m_deftext:

        if (objc !=  4-i) {
            Tcl_WrongNumArgs (interp, 2-i, objv, "<name>"
                              " <constraints script>");
            return TCL_ERROR;
        }
        h = Tcl_CreateHashEntry (&sdata->textDef, Tcl_GetString (objv[2-i]),
                                 &hnew);
................................................................................
            Tcl_SetHashValue (h, pattern);
        } else {
            Tcl_DeleteHashEntry (h);
        }
        break;
        
    case m_start:

        if (objc < 3-i || objc > 4-i) {
            Tcl_WrongNumArgs (interp, 2-i, objv, "<documentElement>"
                              " ?<namespace>?");
            return TCL_ERROR;
        }
        if (sdata->start) {
            FREE (sdata->start);
................................................................................
            }
            sdata->startNamespace =
                tdomstrdup (Tcl_GetString (objv[3-i]));
        }
        break;

    case m_event:

        if (objc < 3) {
            Tcl_WrongNumArgs (interp, 2, objv, "<eventType>"
                              " ?<type specific data>?");
            return TCL_ERROR;
        }
        if (Tcl_GetIndexFromObj (interp, objv[2], eventKeywords,
                                 "keyword", 0, &keywordIndex)
................................................................................

    case m_delete:
        if (objc != 2) {
            Tcl_WrongNumArgs(interp, 2, objv, "");
            return TCL_ERROR;
        }
        Tcl_DeleteCommand(interp, Tcl_GetString(objv[0]));
        break;



    case m_nrForwardDefinitions:
        if (objc != 2) {
            Tcl_WrongNumArgs(interp, 2, objv, "");
            return TCL_ERROR;
        }
        SetIntResult(sdata->forwardPatternDefs);
................................................................................
        default:
            SetResult ("Internal error: Invalid validation state");
            return TCL_ERROR;
        }
        break;

    case m_reset:

        schemaReset (sdata);
        break;

    case m_validate:

        if (objc < 3 || objc > 4) {
            Tcl_WrongNumArgs (interp, 2, objv, "<xml> ?resultVarName?");
            return TCL_ERROR;
        }
        xmlstr = Tcl_GetStringFromObj (objv[2], &len);
        if (validateString (interp, sdata, xmlstr, len) == TCL_OK) {
            SetBooleanResult (1);
................................................................................
            }
            SetBooleanResult (0);
        }
        schemaReset (sdata);
        break;

    case m_domvalidate:

        if (objc < 3 || objc > 4) {
            Tcl_WrongNumArgs (interp, 2, objv, "<xml> ?resultVarName?");
            return TCL_ERROR;
        }
        doc = tcldom_getDocumentFromName (interp, Tcl_GetString (objv[2]),
                                          &errMsg);
        if (doc) {
................................................................................
                            Tcl_GetStringResult (interp), 0);
            }
            SetBooleanResult (0);
        }
        schemaReset (sdata);
        break;



















    default:
        Tcl_SetResult (interp, "unknown method", NULL);
        result = TCL_ERROR;
        break;




    }
    return result;
}

 
/*
 *----------------------------------------------------------------------------
................................................................................
        }
        ind = 2;
    }

    Tcl_ResetResult (interp);
    switch ((enum schemaMethod) methodIndex) {
    case m_create:
        sdata = initSchemaData ();
        Tcl_CreateObjCommand (interp, Tcl_GetString(objv[ind]),
                              schemaInstanceCmd,
                              (ClientData) sdata,
                              schemaInstanceDelete);
        Tcl_SetObjResult (interp, objv[ind]);
        break;

................................................................................
    sdata->cp = pattern;
    sdata->contentSize = CONTENT_ARRAY_SIZE_INIT;
    sdata->numAttr = 0;
    sdata->numReqAttr = 0;
    sdata->currentAttrs = NULL;
    sdata->attrSize = 0;


    result = Tcl_EvalObjEx (interp, definition, TCL_EVAL_DIRECT);


    pattern->attrs = sdata->currentAttrs;
    pattern->numAttr = sdata->numAttr;
    pattern->numReqAttr = sdata->numReqAttr;
    /* ... and restore the previously saved sdata states  */
    sdata->cp = savedCP;
    sdata->contentSize = savedContenSize;
................................................................................
        }
        pattern = initSchemaCP (
            SCHEMA_CTYPE_NAME,
            sdata->currentNamespace,
            Tcl_GetHashKey (hashTable, entryPtr)
            );
        pattern->flags |= LOCAL_DEFINED_ELEMENT;
        evalDefinition (interp, sdata, objv[3], pattern, quant, n, m);
    }
    return TCL_OK;
}

/* Implements the schema definition commands "choice", "group",
 * "interleave" and "mixed" */
static int
................................................................................

static int maybeAddAttr (
    Tcl_Interp *interp,
    SchemaData *sdata,
    Tcl_Obj *nameObj,
    Tcl_Obj *namespaceObj,
    Tcl_Obj *scriptObj,
    int required

    )
{
    Tcl_HashEntry *h;
    int hnew, hnew1, i, result = TCL_OK;
    char *name, *namespace = NULL;
    SchemaAttr *attr;
    SchemaCP *cp;
................................................................................
        cp = initSchemaCP (SCHEMA_CTYPE_CHOICE, NULL, NULL);
        cp->type = SCHEMA_CTYPE_TEXT;
        REMEMBER_PATTERN (cp)
        sdata->isAttributeConstaint = 1;
        result = evalConstraints (interp, sdata, cp, scriptObj);
        sdata->isAttributeConstaint = 0;
        attr->cp = cp;


    } else {
        attr->cp = NULL;
    }
    if (!sdata->currentAttrs) {
        sdata->currentAttrs = MALLOC (sizeof(SchemaAttr*)
                                      * ATTR_ARRAY_INIT);
        sdata->attrSize = ATTR_ARRAY_INIT;
................................................................................
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[]
    )
{
    SchemaData *sdata = GETASI;
    char *quantStr;
    int len, required = 1, scriptIndex, i;
    Tcl_Obj *nsobj;



    CHECK_SI
    CHECK_TOPLEVEL

    if (clientData) {

        checkNrArgs (3,5,"Expected: name namespace"
                     " | name namespace attquant"
                     " | name namespace <constraint script>"
                     " | name namespace attquant <constraint script>");
        i = 1;
        nsobj = objv[2];
    } else {
        checkNrArgs (2,4,"Expected: name"

                     " | name attquant"
                     " | name <constraint script>"
                     " | name attquant <constraint script>");
        i = 0;
        nsobj = NULL;
    }





    if (objc == 2+i) {
        return maybeAddAttr (interp, sdata, objv[1], nsobj, NULL, 1);
    }
    quantStr = Tcl_GetStringFromObj (objv[2+i], &len);
    if (len == 1) {
        if (quantStr[0] == '?') {
            required = 0;
        } else if (quantStr[0] != '!') {
            SetResult ("Invalid attribute quant");
            return TCL_ERROR;
        }
        if (objc == 3+i) {
            return maybeAddAttr (interp, sdata, objv[1], nsobj, NULL,
                                 required);
        }
        scriptIndex = 3+i;












    } else {
        if (objc == 4+i) {
            SetResult ("Invalid attribute quant");





            return TCL_ERROR;
        }
        scriptIndex = 2+i;




    }

    return maybeAddAttr (interp, sdata, objv[1], nsobj,
                         objv[scriptIndex], required);




}

static int
NamespacePatternObjCmd (
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
................................................................................
                                    Tcl_GetString(objv[1]), &hnew);
    if (entryPtr == sdata->emptyNamespace) {
        sdata->currentNamespace = NULL;
    } else {
        sdata->currentNamespace = (char *)
            Tcl_GetHashKey (&sdata->namespace, entryPtr);
    }

    result = Tcl_EvalObjEx (interp, objv[2], TCL_EVAL_DIRECT);

    sdata->currentNamespace = currentNamespace;
    return result;
}

static int
TextPatternObjCmd (
    ClientData clientData,
................................................................................
    } else if (objc == 2) {
        quant = SCHEMA_CQUANT_ONE;
        pattern = initSchemaCP (SCHEMA_CTYPE_CHOICE, NULL, NULL);
        pattern->type = SCHEMA_CTYPE_TEXT;
    } else {
        h = Tcl_FindHashEntry (&sdata->textDef, Tcl_GetString (objv[2]));
        if (!h) {
            SetResult ("Unknown text type");
            return TCL_ERROR;
        }
        pattern = (SchemaCP *) Tcl_GetHashValue (h);
        sdata->cp->flags |= CONSTRAINT_TEXT_CHILD;
    }
    if (objc < 3) {
        REMEMBER_PATTERN (pattern)
................................................................................
    return TCL_OK;
}

typedef struct
{
    int nrArg;
    Tcl_Obj **evalStub;

} tclTCData;

static void
tclImplFree (
    void *constraintData
    )
{
................................................................................
    )
{
    tclTCData *tcdata = constraintData;
    int result, bool;

    tcdata->evalStub[tcdata->nrArg-1] = Tcl_NewStringObj(text, -1);
    Tcl_IncrRefCount (tcdata->evalStub[tcdata->nrArg-1]);

    result = Tcl_EvalObjv (interp, tcdata->nrArg, tcdata->evalStub,
                           TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL);

    Tcl_DecrRefCount (tcdata->evalStub[tcdata->nrArg-1]);
    if (result != TCL_OK) {
        return 0;
    }
    result = Tcl_GetBooleanFromObj (interp, Tcl_GetObjResult (interp), &bool);
    if (result != TCL_OK) {
        return 0;
................................................................................
    tcdata = TMALLOC (tclTCData);
    tcdata->nrArg = objc;
    tcdata->evalStub = MALLOC (sizeof (Tcl_Obj*) * objc);
    for (i = 1; i < objc; i++) {
        tcdata->evalStub[i-1] = objv[i];
        Tcl_IncrRefCount (tcdata->evalStub[i-1]);
    }

    sc->constraintData = tcdata;
    return TCL_OK;
}

static void
fixedImplFree (
    void *constraintData
................................................................................
static int
matchImpl (
    Tcl_Interp *interp,
    void *constraintData,
    char *text
    )
{












    if (Tcl_StringMatch (text, Tcl_GetString ((Tcl_Obj *) constraintData)))

        return 1;
    return 0;
}

static int
matchTCObjCmd (
    ClientData clientData,
................................................................................
    )
{
    SchemaData *sdata = GETASI;
    SchemaConstraint *sc;

    CHECK_TI
    CHECK_TOPLEVEL



    checkNrArgs (2,2,"Expected: <match pattern>");




    ADD_CONSTRAINT (sdata, sc)

    sc->constraint = matchImpl;



    sc->freeData = matchImplFree;
    Tcl_IncrRefCount (objv[1]);
    sc->constraintData = objv[1];
    return TCL_OK;
}

static void
................................................................................
        /* A bce date */
        text++;
    }
    for (i = 0; i < 4; i++) {
        if (*text < '0' || *text > '9') return 0;
        text++;
    }

    if (*text != '-') return 0;
    y = atoi(text-4);
    /* There isn't a year 0. it's either 0001 or -0001 */
    if (y == 0) return 0;
    text++;
    for (i = 0; i < 2; i++) {
        if (*text < '0' || *text > '9') return 0;
................................................................................
    Tcl_Interp *interp
    )
{
    /* Inline definition commands. */
    Tcl_CreateObjCommand (interp, "tdom::schema::defelement",
                          schemaInstanceCmd, NULL, NULL);
    Tcl_CreateObjCommand (interp, "tdom::schema::defpattern",


                          schemaInstanceCmd, NULL, NULL);
    Tcl_CreateObjCommand (interp, "tdom::schema::start",
                          schemaInstanceCmd, NULL, NULL);

    /* The "any" definition command. */
    Tcl_CreateObjCommand (interp, "tdom::schema::any",
                          AnyPatternObjCmd, NULL, NULL);






|







 







<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
>


|
>



>
>
>







 







>
>
>
>
>
>
>
>
>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
|
<
|

>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|
|
>


|
|
|







 







|


|
|







 







>







 







<
<
<
<
<
<
|
<










>
|
<
>







 







>




>
|
|
|
|
>








>
|
<
>








>







 







>







 







>







 







|
>
>







 







>




>







 







>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





>
>
>







 







|







 







>

>







 







|







 







|
>







 







>
>







 







|
|
|
>
>





>
|

|
|
<
|

|
>

|
<
|
|

>
>
>
>
|
|
|

|

|

|



|
|
|

|
>
>
>
>
>
>
>
>
>
>
>
>
|
<
|
>
>
>
>
>


<
>
>
>
>
|
>
|
|
>
>
>
>







 







>

>







 







|







 







>







 







>

|
>







 







>







 







>
>
>
>
>
>
>
>
>
>
>
>
|
>







 







>
>
>
|
>
>
>
>

>
|
>
>
>







 







>







 







>
>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
...
137
138
139
140
141
142
143

144
145
146
147
148
149
150
...
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
...
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
...
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
...
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
...
677
678
679
680
681
682
683


































684
685
686
687
688
689
690
...
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
...
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
....
1998
1999
2000
2001
2002
2003
2004
2005
2006

2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
....
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
....
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
....
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
....
2229
2230
2231
2232
2233
2234
2235






2236

2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248

2249
2250
2251
2252
2253
2254
2255
2256
....
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293

2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
....
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
....
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
....
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
....
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
....
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
....
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
....
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
....
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
....
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
....
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
....
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
....
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009

3010
3011
3012
3013
3014
3015

3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052

3053
3054
3055
3056
3057
3058
3059
3060

3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
....
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
....
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
....
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
....
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
....
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
....
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
....
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
....
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
....
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
|   License for the specific language governing rights and limitations
|   under the License.
|
|   Contributor(s):
|
|
|   written by Rolf Ade
|   2018-2019
|
\---------------------------------------------------------------------------*/

#ifndef TDOM_NO_SCHEMA

#include <tdom.h>
#include <tcldom.h>
................................................................................
    SchemaData **schemaInfoPtr = Tcl_GetThreadData(&activeSchemaData,
                                                        sizeof (SchemaData*));
    *schemaInfoPtr = v;
}
# define SETASI(v) SetActiveSchemaData (v)
#endif


#define CHECK_SI                                                        \
    if (!sdata) {                                                       \
        SetResult ("Command called outside of schema context");         \
        return TCL_ERROR;                                               \
    }                                                                   \
    if (sdata->isTextConstraint) {                                      \
        SetResult ("Command called in invalid schema context");         \
................................................................................
#define CHECK_TOPLEVEL                                                  \
    if (sdata->defineToplevel) {                                        \
        SetResult("Command not allowed at top level "                   \
                  "in schema define evaluation");                       \
        return TCL_ERROR;                                               \
    }

#define CHECK_RECURSIVE_CALL                                            \
    if (clientData != NULL) {                                           \
        savedsdata = GETASI;                                            \
        if (savedsdata == sdata) {                                      \
            SetResult ("This recursive call is not allowed"); \
            return TCL_ERROR;                                           \
        }                                                               \
    }
      
#define CHECK_EVAL                                                      \
    if (sdata->currentEvals) {                                          \
        SetResult ("Method not allowed in nested schema define script"); \
        return TCL_ERROR;                                               \
    }
    
#define REMEMBER_PATTERN(pattern)                                       \
    if (sdata->numPatternList == sdata->patternListSize) {              \
        sdata->patternList = (SchemaCP **) REALLOC (                    \
            sdata->patternList,                                         \
            sizeof (SchemaCP*) * sdata->patternListSize * 2);           \
        sdata->patternListSize *= 2;                                    \
    }                                                                   \
................................................................................
                     * sizeof (SchemaQuant));                           \
        sdata->contentSize *= 2;                                        \
    }                                                                   \
    sdata->cp->content[sdata->cp->nc] = (SchemaCP *) sc;                \
    sdata->cp->quants[sdata->cp->nc] = SCHEMA_CQUANT_ONE;               \
    sdata->cp->nc++;                                                    \

#define maxOne(quant) \
    ((quant) == SCHEMA_CQUANT_ONE || (quant) == SCHEMA_CQUANT_OPT) ? 1 : 0

#define minOne(quant) \
    ((quant) == SCHEMA_CQUANT_ONE || (quant) == SCHEMA_CQUANT_PLUS) ? 1 : 0

#define mayRepeat(quant) \
    ((quant) == SCHEMA_CQUANT_REP || (quant) == SCHEMA_CQUANT_PLUS) ? 1 : 0

#define mayMiss(quant) \
    ((quant) == SCHEMA_CQUANT_REP || (quant) == SCHEMA_CQUANT_OPT) ? 1 : 0

#define hasMatched(quant,hm) \
    (hm) == 0 ?  mayMiss(quant) :  1

#define mustMatch(quant,hm) \
    (hm) == 0 ? minOne(quant) : 0


#define getContext(cp, ac, hm)        \
    cp = se->pattern;                 \
    ac = se->activeChild;             \
    hm = se->hasMatched;


#define updateStack(se,cp,ac)                     \
    if (maxOne (cp->quants[ac])) {                \
        se->activeChild = ac + 1;                 \
        se->hasMatched = 0;                       \
    } else {                                      \
        se->activeChild = ac;                     \
        se->hasMatched = 1;                       \
    }

#define serializeElementName(rObj, cp)                  \
    rObj = Tcl_NewObj();                                \
    if (cp->namespace) {                                \
        Tcl_SetStringObj (rObj, cp->namespace, -1);     \
        Tcl_AppendToObj (rObj, ":", 1);                 \
    }                                                   \
    Tcl_AppendToObj (rObj, cp->name, -1);

static SchemaCP*
initSchemaCP (
    Schema_CP_Type type,
    void *namespace,
    char *name
    )
{
................................................................................
        }
        break;
    }
    FREE (pattern);
}

static SchemaData*
initSchemaData (
    Tcl_Obj *cmdNameObj)
{
    SchemaData *sdata;
    int hnew, len;
    char *name;

    sdata = TMALLOC (SchemaData);
    memset (sdata, 0, sizeof(SchemaData));
    name = Tcl_GetStringFromObj (cmdNameObj, &len);
    sdata->self = Tcl_NewStringObj (name, len);
    Tcl_IncrRefCount (sdata->self);
    Tcl_InitHashTable (&sdata->element, TCL_STRING_KEYS);
    Tcl_InitHashTable (&sdata->pattern, TCL_STRING_KEYS);
    Tcl_InitHashTable (&sdata->attrNames, TCL_STRING_KEYS);
    Tcl_InitHashTable (&sdata->namespace, TCL_STRING_KEYS);
    Tcl_InitHashTable (&sdata->textDef, TCL_STRING_KEYS);
    sdata->emptyNamespace = Tcl_CreateHashEntry (
        &sdata->namespace, "", &hnew);
................................................................................
    ClientData clientData
    )
{
    SchemaData *sdata = (SchemaData *) clientData;
    unsigned int i;
    SchemaValidationStack *down;

    /* Protect the clientData to be freed inside (even nested)
     * Tcl_Eval*() calls to avoid invalid mem access and postpone the
     * cleanup until the Tcl_Eval*() calls are finished (done in
     * schemaInstanceCmd(). */
    if (sdata->currentEvals) {
        sdata->cleanupAfterEval = 1;
        return;
    }
    Tcl_DecrRefCount (sdata->self);
    if (sdata->start) FREE (sdata->start);
    if (sdata->startNamespace) FREE (sdata->startNamespace);
    Tcl_DeleteHashTable (&sdata->namespace);
    Tcl_DeleteHashTable (&sdata->element);
    Tcl_DeleteHashTable (&sdata->pattern);
    Tcl_DeleteHashTable (&sdata->attrNames);
    Tcl_DeleteHashTable (&sdata->textDef);
................................................................................
    if (pattern->type == SCHEMA_CTYPE_INTERLEAVE) {
        stackElm->interleaveState = MALLOC (sizeof (int) * pattern->nc);
        memset (stackElm->interleaveState, 0, sizeof (int) * pattern->nc);
    }
    sdata->stack = stackElm;
}



































static void
popStack (
    SchemaData *sdata
    )
{
    SchemaValidationStack *se;
    DBG(fprintf(stderr, "pop from Stack:\n");serializeCP(sdata->stack->pattern));
................................................................................
    char *namespace
    )
{
    SchemaCP *cp, *candidate, *icp;
    int hm, ac, i, mayskip, rc;
    int isName = 0;
    SchemaValidationStack *se;
    Tcl_Obj *cmdPtr;

    if (!sdata->stack) return 0;
    se = sdata->stack;
    getContext (cp, ac, hm);

    switch (cp->type) {
    case SCHEMA_CTYPE_NAME:
................................................................................
        while (ac < cp->nc) {
            candidate = cp->content[ac];
            mayskip = 0;
            switch (candidate->type) {
            case SCHEMA_CTYPE_TEXT:
                if (candidate->nc) {
                    if (!checkText (interp, candidate, "")) {
                        if (sdata->reportCmd) {
                            cmdPtr = Tcl_DuplicateObj (sdata->reportCmd);
                            Tcl_ListObjAppendElement (interp, cmdPtr,
                                                      sdata->self);
                            Tcl_ListObjAppendElement (
                                interp, cmdPtr,
                                Tcl_NewStringObj ("MISSING_TEXT", 22)
                                );
                            sdata->currentEvals++;
                            rc = Tcl_EvalObjEx (interp, cmdPtr,
                                                TCL_EVAL_GLOBAL
                                                | TCL_EVAL_DIRECT);
                            sdata->currentEvals--;
                            Tcl_DecrRefCount (cmdPtr);
                            if (rc != TCL_OK) {
                                return 0;
                            }
                            break;
                        }
                        
                        return 0;
                    }
                }
                break;

            case SCHEMA_CTYPE_ANY:
                updateStack (se, cp, ac);
................................................................................
    savedContenSize = sdata->contentSize;
    savedIsTextConstraint = sdata->isTextConstraint;
    /* ... and prepare sdata for definition evaluation. */
    sdata->cp = cp;
    sdata->contentSize = CONTENT_ARRAY_SIZE_INIT;
    sdata->isTextConstraint = 1;
    sdata->textStub[3] = script;
    sdata->currentEvals++;
    result = Tcl_EvalObjv (interp, 4, sdata->textStub, TCL_EVAL_GLOBAL);

    sdata->currentEvals--;
    /* ... and restore the previously saved sdata states  */
    sdata->isTextConstraint = savedIsTextConstraint;
    sdata->cp = savedCP;
    sdata->contentSize = savedContenSize;
    if (sdata->cp && !sdata->isAttributeConstaint && cp->nc) {
        sdata->cp->flags |= CONSTRAINT_TEXT_CHILD;
    }
    return result;
}

static int
schemaInstanceInfoCmd (
    SchemaData *sdata,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[]
    )
{
    int methodIndex;
    Tcl_HashEntry *h;
    Tcl_HashSearch search;
    SchemaCP *cp;
    SchemaValidationStack *se;
    Tcl_Obj *resultObj, *elmObj;
    
    static const char *schemaInstanceInfoMethods[] = {
        "defelements", "stack", NULL
    };
    enum schemaInstanceInfoMethod {
        m_defelements, m_stack
    };

    static const char *schemaInstanceInfoStackMethods[] = {
        "top", "inside", NULL
    };
    enum schemaInstanceInfoStackMethod {
        m_top, m_inside
    };
    
    if (objc < 2) {
        Tcl_WrongNumArgs (interp, 1, objv, "subcommand ?arguments?");
        return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObj (interp, objv[1], schemaInstanceInfoMethods,
                             "method", 0, &methodIndex)
        != TCL_OK) {
        return TCL_ERROR;
    }
    
    Tcl_ResetResult (interp);
    switch ((enum schemaInstanceInfoMethod) methodIndex) {
    case m_defelements:
        if (objc != 2) {
            Tcl_WrongNumArgs (interp, 1, objv, "defelements");
            return TCL_ERROR;
        }
        resultObj = Tcl_GetObjResult (interp);
        for (h = Tcl_FirstHashEntry (&sdata->element, &search);
             h != NULL;
             h = Tcl_NextHashEntry (&search)) {
            cp = (SchemaCP *) Tcl_GetHashValue (h);
            if (!cp) continue;
            if (cp->flags & FORWARD_PATTERN_DEF
                || cp->flags & PLACEHOLDER_PATTERN_DEF) continue;
            serializeElementName (elmObj, cp);
            if (Tcl_ListObjAppendElement (interp, resultObj, elmObj) != TCL_OK)
                return TCL_ERROR;
        }
        break;

    case m_stack:
        if (Tcl_GetIndexFromObj (interp, objv[1],
                                 schemaInstanceInfoStackMethods,
                                 "method", 0, &methodIndex)
            != TCL_OK) {
            return TCL_ERROR;
        }
        switch ((enum schemaInstanceInfoStackMethod) methodIndex) {
        case m_top:
            break;
        case m_inside:
            if (!sdata->stack) {
                Tcl_ResetResult (interp);
                return TCL_OK;
            }
            se = sdata->stack;
            while (se->pattern->type != SCHEMA_CTYPE_NAME) {
                se = se->down;
            }
            serializeElementName (elmObj, se->pattern);
            Tcl_SetObjResult (interp, elmObj);
            return TCL_OK;
            break;
        }
        
    }
    
    return TCL_OK;
}

int
schemaInstanceCmd (
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[]
................................................................................
    SchemaCP      *pattern, *current = NULL;
    void          *namespacePtr, *savedNamespacePtr;
    char          *xmlstr, *errMsg;
    domDocument   *doc;
    domNode       *node;

    static const char *schemaInstanceMethods[] = {
        "defelement", "defpattern",  "start",   "event", "delete",
        "nrForwardDefinitions",      "state",   "reset", "define",
        "validate",   "domvalidate", "deftext", "info",  "reportcmd",
        NULL
    };
    enum schemaInstanceMethod {
        m_defelement,  m_defpattern,  m_start,   m_event, m_delete,
        m_nrForwardDefinitions,       m_state,   m_reset, m_define,
        m_validate,    m_domvalidate, m_deftext, m_info,  m_reportcmd
    };

    static const char *eventKeywords[] = {
        "start", "end", "text", NULL
    };

    enum eventKeyword
................................................................................

    if (objc < 2) {
        Tcl_WrongNumArgs (interp, 1, objv, "subcommand ?arguments?");
        return TCL_ERROR;
    }

    if (sdata == NULL) {
        /* Inline defined defelement, defpattern, deftext or start */
        sdata = GETASI;
        CHECK_SI;
        if (!sdata->defineToplevel && sdata->currentEvals > 1) {
            SetResult ("Method not allowed in nested schema define script");
            return TCL_ERROR;
        }
        i = 1;
    }

    if (Tcl_GetIndexFromObj (interp, objv[1-i], schemaInstanceMethods,
                             "method", 0, &methodIndex)
................................................................................
        return TCL_ERROR;
    }

    Tcl_ResetResult (interp);
    switch ((enum schemaInstanceMethod) methodIndex) {
    case m_defelement:
    case m_defpattern:
        CHECK_RECURSIVE_CALL
        if (objc != 4-i && objc != 5-i) {
            Tcl_WrongNumArgs (interp, 1-i, objv, "<name>"
                 " ?<namespace>? pattern");
            return TCL_ERROR;
        }
        if ((enum schemaInstanceMethod) methodIndex == m_defelement) {
            hashTable = &sdata->element;
................................................................................
                current = (SchemaCP *) Tcl_GetHashValue (h);
                pattern->next = current;
            }
            REMEMBER_PATTERN (pattern);
            Tcl_SetHashValue (h, pattern);
        }







        SETASI(sdata);

        savedDefineToplevel = sdata->defineToplevel;
        savedNamespacePtr = sdata->currentNamespace;
        sdata->defineToplevel = 0;
        sdata->currentNamespace = namespacePtr;
        sdata->cp = pattern;
        sdata->numAttr = 0;
        sdata->numReqAttr = 0;
        sdata->currentAttrs = NULL;
        sdata->contentSize = CONTENT_ARRAY_SIZE_INIT;
        sdata->evalStub[3] = objv[patternIndex];
        sdata->currentEvals++;
        result = Tcl_EvalObjv (interp, 4, sdata->evalStub, TCL_EVAL_GLOBAL);

        sdata->currentEvals--;
        sdata->currentNamespace = NULL;
        pattern->attrs = sdata->currentAttrs;
        pattern->numAttr = sdata->numAttr;
        pattern->numReqAttr = sdata->numReqAttr;
        if (result == TCL_OK) {
            if (forwardDef) {
                if (pattern->flags & FORWARD_PATTERN_DEF) {
................................................................................
        sdata->currentNamespace = savedNamespacePtr;
        if (!savedDefineToplevel) {
            SETASI(savedsdata);
        }
        break;

    case m_define:
        CHECK_EVAL
        if (objc != 3) {
            Tcl_WrongNumArgs (interp, 2, objv, "<definition commands>");
            return TCL_ERROR;
        }
        if (clientData) {
            savedsdata = GETASI;
            if (savedsdata == sdata) {
                SetResult ("Recursive call of schema command is not allowed");
                return TCL_ERROR;
            }
        }
        SETASI(sdata);
        savedNumPatternList = sdata->numPatternList;
        sdata->currentNamespace = 0;
        sdata->cp = NULL;
        sdata->contentSize = 0;
        sdata->defineToplevel = 1;
        sdata->evalStub[3] = objv[2];
        sdata->currentEvals++;
        result = Tcl_EvalObjv (interp, 4, sdata->evalStub, TCL_EVAL_GLOBAL);

        sdata->currentEvals--;
        if (result != TCL_OK) {
            cleanupLastPattern (sdata, savedNumPatternList);
        }
        sdata->defineToplevel = 0;
        SETASI(savedsdata);
        break;

    case m_deftext:
        CHECK_RECURSIVE_CALL
        if (objc !=  4-i) {
            Tcl_WrongNumArgs (interp, 2-i, objv, "<name>"
                              " <constraints script>");
            return TCL_ERROR;
        }
        h = Tcl_CreateHashEntry (&sdata->textDef, Tcl_GetString (objv[2-i]),
                                 &hnew);
................................................................................
            Tcl_SetHashValue (h, pattern);
        } else {
            Tcl_DeleteHashEntry (h);
        }
        break;
        
    case m_start:
        CHECK_RECURSIVE_CALL
        if (objc < 3-i || objc > 4-i) {
            Tcl_WrongNumArgs (interp, 2-i, objv, "<documentElement>"
                              " ?<namespace>?");
            return TCL_ERROR;
        }
        if (sdata->start) {
            FREE (sdata->start);
................................................................................
            }
            sdata->startNamespace =
                tdomstrdup (Tcl_GetString (objv[3-i]));
        }
        break;

    case m_event:
        CHECK_EVAL
        if (objc < 3) {
            Tcl_WrongNumArgs (interp, 2, objv, "<eventType>"
                              " ?<type specific data>?");
            return TCL_ERROR;
        }
        if (Tcl_GetIndexFromObj (interp, objv[2], eventKeywords,
                                 "keyword", 0, &keywordIndex)
................................................................................

    case m_delete:
        if (objc != 2) {
            Tcl_WrongNumArgs(interp, 2, objv, "");
            return TCL_ERROR;
        }
        Tcl_DeleteCommand(interp, Tcl_GetString(objv[0]));
        /* We return immediately here to avoid clashes with postponed
           sdata cleanup at the end of the function. */
        return TCL_OK;

    case m_nrForwardDefinitions:
        if (objc != 2) {
            Tcl_WrongNumArgs(interp, 2, objv, "");
            return TCL_ERROR;
        }
        SetIntResult(sdata->forwardPatternDefs);
................................................................................
        default:
            SetResult ("Internal error: Invalid validation state");
            return TCL_ERROR;
        }
        break;

    case m_reset:
        CHECK_EVAL
        schemaReset (sdata);
        break;

    case m_validate:
        CHECK_EVAL
        if (objc < 3 || objc > 4) {
            Tcl_WrongNumArgs (interp, 2, objv, "<xml> ?resultVarName?");
            return TCL_ERROR;
        }
        xmlstr = Tcl_GetStringFromObj (objv[2], &len);
        if (validateString (interp, sdata, xmlstr, len) == TCL_OK) {
            SetBooleanResult (1);
................................................................................
            }
            SetBooleanResult (0);
        }
        schemaReset (sdata);
        break;

    case m_domvalidate:
        CHECK_EVAL
        if (objc < 3 || objc > 4) {
            Tcl_WrongNumArgs (interp, 2, objv, "<xml> ?resultVarName?");
            return TCL_ERROR;
        }
        doc = tcldom_getDocumentFromName (interp, Tcl_GetString (objv[2]),
                                          &errMsg);
        if (doc) {
................................................................................
                            Tcl_GetStringResult (interp), 0);
            }
            SetBooleanResult (0);
        }
        schemaReset (sdata);
        break;

    case m_info:
        objv++;
        objc--;
        result = schemaInstanceInfoCmd (sdata, interp, objc, objv);
        break;

    case m_reportcmd:
        if (objc != 3) {
            Tcl_WrongNumArgs (interp, 2, objv, "<tcl-cmd>");
            return TCL_ERROR;
        }
        if (sdata->reportCmd) {
            Tcl_DecrRefCount (sdata->reportCmd);
        }
        sdata->reportCmd = objv[2];
        Tcl_IncrRefCount (sdata->reportCmd);
        break;

    default:
        Tcl_SetResult (interp, "unknown method", NULL);
        result = TCL_ERROR;
        break;

    }
    if (sdata->cleanupAfterEval && sdata->currentEvals == 0) {
        schemaInstanceDelete (sdata);
    }
    return result;
}

 
/*
 *----------------------------------------------------------------------------
................................................................................
        }
        ind = 2;
    }

    Tcl_ResetResult (interp);
    switch ((enum schemaMethod) methodIndex) {
    case m_create:
        sdata = initSchemaData (objv[ind]);
        Tcl_CreateObjCommand (interp, Tcl_GetString(objv[ind]),
                              schemaInstanceCmd,
                              (ClientData) sdata,
                              schemaInstanceDelete);
        Tcl_SetObjResult (interp, objv[ind]);
        break;

................................................................................
    sdata->cp = pattern;
    sdata->contentSize = CONTENT_ARRAY_SIZE_INIT;
    sdata->numAttr = 0;
    sdata->numReqAttr = 0;
    sdata->currentAttrs = NULL;
    sdata->attrSize = 0;

    sdata->currentEvals++;
    result = Tcl_EvalObjEx (interp, definition, TCL_EVAL_DIRECT);
    sdata->currentEvals--;

    pattern->attrs = sdata->currentAttrs;
    pattern->numAttr = sdata->numAttr;
    pattern->numReqAttr = sdata->numReqAttr;
    /* ... and restore the previously saved sdata states  */
    sdata->cp = savedCP;
    sdata->contentSize = savedContenSize;
................................................................................
        }
        pattern = initSchemaCP (
            SCHEMA_CTYPE_NAME,
            sdata->currentNamespace,
            Tcl_GetHashKey (hashTable, entryPtr)
            );
        pattern->flags |= LOCAL_DEFINED_ELEMENT;
        return evalDefinition (interp, sdata, objv[3], pattern, quant, n, m);
    }
    return TCL_OK;
}

/* Implements the schema definition commands "choice", "group",
 * "interleave" and "mixed" */
static int
................................................................................

static int maybeAddAttr (
    Tcl_Interp *interp,
    SchemaData *sdata,
    Tcl_Obj *nameObj,
    Tcl_Obj *namespaceObj,
    Tcl_Obj *scriptObj,
    int required,
    SchemaCP *type
    )
{
    Tcl_HashEntry *h;
    int hnew, hnew1, i, result = TCL_OK;
    char *name, *namespace = NULL;
    SchemaAttr *attr;
    SchemaCP *cp;
................................................................................
        cp = initSchemaCP (SCHEMA_CTYPE_CHOICE, NULL, NULL);
        cp->type = SCHEMA_CTYPE_TEXT;
        REMEMBER_PATTERN (cp)
        sdata->isAttributeConstaint = 1;
        result = evalConstraints (interp, sdata, cp, scriptObj);
        sdata->isAttributeConstaint = 0;
        attr->cp = cp;
    } else if (type) {
        attr->cp = type;
    } else {
        attr->cp = NULL;
    }
    if (!sdata->currentAttrs) {
        sdata->currentAttrs = MALLOC (sizeof(SchemaAttr*)
                                      * ATTR_ARRAY_INIT);
        sdata->attrSize = ATTR_ARRAY_INIT;
................................................................................
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[]
    )
{
    SchemaData *sdata = GETASI;
    char *str;
    int len, required = 1;
    Tcl_Obj *nsObj, *nameObj;
    Tcl_HashEntry *h;
    SchemaCP *type;

    CHECK_SI
    CHECK_TOPLEVEL

    if (clientData) {
        checkNrArgs (3,6,"Expected:"
                     "  name namespace"
                     " | name namespace attquant"
                     " | name namespace ?attquant? <constraint script>"
                     " | name namespace ?attquant? \"type\" typename");

        nsObj = objv[2];
    } else {
        checkNrArgs (2,5,"Expected:"
                     "  name"
                     " | name attquant"
                     " | name ?attquant? <constraint script>"

                     " | name ?attquant? \"type\" typename");
        nsObj = NULL;
    }
    nameObj = objv[1];
    if (clientData) {
        objv++;
        objc--;
    }
    if (objc == 2) {
        return maybeAddAttr (interp, sdata, nameObj, nsObj, NULL, 1, NULL);
    }
    str = Tcl_GetStringFromObj (objv[2], &len);
    if (len == 1) {
        if (str[0] == '?') {
            required = 0;
        } else if (str[0] != '!') {
            SetResult ("Invalid attribute quant");
            return TCL_ERROR;
        }
        if (objc == 3) {
            return maybeAddAttr (interp, sdata, nameObj, nsObj, NULL,
                                 required, NULL);
        }
        objv++;
        objc--;
        str = Tcl_GetStringFromObj (objv[2], &len);
    }
    if (objc == 4) {
        if (len != 4
            || strcmp("type", str) != 0) {
            if (clientData) {
                SetResult ("Expected:"
                           "  name namespace"
                           " | name namespace attquant"
                           " | name namespace ?attquant? <constraint script>"
                           " | name namespace ?attquant? \"type\" typename");
            } else {

                SetResult ("Expected:"
                           "  name"
                           " | name attquant"
                           " | name ?attquant? <constraint script>"
                           " | name ?attquant? \"type\" typename");
            }
            return TCL_ERROR;
        }

        h = Tcl_FindHashEntry (&sdata->textDef, Tcl_GetString (objv[3]));
        if (!h) {
            SetResult3 ("Unknown text type \"", Tcl_GetString (objv[3]), "\"");
            return TCL_ERROR;
        }
        type = (SchemaCP *) Tcl_GetHashValue (h);
        return maybeAddAttr (interp, sdata, nameObj, nsObj, NULL,
                             required, type);        
    } else {
        return maybeAddAttr (interp, sdata, nameObj, nsObj, objv[2],
                             required, NULL);
    }
}

static int
NamespacePatternObjCmd (
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
................................................................................
                                    Tcl_GetString(objv[1]), &hnew);
    if (entryPtr == sdata->emptyNamespace) {
        sdata->currentNamespace = NULL;
    } else {
        sdata->currentNamespace = (char *)
            Tcl_GetHashKey (&sdata->namespace, entryPtr);
    }
    sdata->currentEvals++;
    result = Tcl_EvalObjEx (interp, objv[2], TCL_EVAL_DIRECT);
    sdata->currentEvals--;
    sdata->currentNamespace = currentNamespace;
    return result;
}

static int
TextPatternObjCmd (
    ClientData clientData,
................................................................................
    } else if (objc == 2) {
        quant = SCHEMA_CQUANT_ONE;
        pattern = initSchemaCP (SCHEMA_CTYPE_CHOICE, NULL, NULL);
        pattern->type = SCHEMA_CTYPE_TEXT;
    } else {
        h = Tcl_FindHashEntry (&sdata->textDef, Tcl_GetString (objv[2]));
        if (!h) {
            SetResult3 ("Unknown text type \"", Tcl_GetString (objv[2]), "\"");
            return TCL_ERROR;
        }
        pattern = (SchemaCP *) Tcl_GetHashValue (h);
        sdata->cp->flags |= CONSTRAINT_TEXT_CHILD;
    }
    if (objc < 3) {
        REMEMBER_PATTERN (pattern)
................................................................................
    return TCL_OK;
}

typedef struct
{
    int nrArg;
    Tcl_Obj **evalStub;
    SchemaData *sdata;
} tclTCData;

static void
tclImplFree (
    void *constraintData
    )
{
................................................................................
    )
{
    tclTCData *tcdata = constraintData;
    int result, bool;

    tcdata->evalStub[tcdata->nrArg-1] = Tcl_NewStringObj(text, -1);
    Tcl_IncrRefCount (tcdata->evalStub[tcdata->nrArg-1]);
    tcdata->sdata->currentEvals++;
    result = Tcl_EvalObjv (interp, tcdata->nrArg, tcdata->evalStub,
                           TCL_EVAL_GLOBAL);
    tcdata->sdata->currentEvals--;
    Tcl_DecrRefCount (tcdata->evalStub[tcdata->nrArg-1]);
    if (result != TCL_OK) {
        return 0;
    }
    result = Tcl_GetBooleanFromObj (interp, Tcl_GetObjResult (interp), &bool);
    if (result != TCL_OK) {
        return 0;
................................................................................
    tcdata = TMALLOC (tclTCData);
    tcdata->nrArg = objc;
    tcdata->evalStub = MALLOC (sizeof (Tcl_Obj*) * objc);
    for (i = 1; i < objc; i++) {
        tcdata->evalStub[i-1] = objv[i];
        Tcl_IncrRefCount (tcdata->evalStub[i-1]);
    }
    tcdata->sdata = sdata;
    sc->constraintData = tcdata;
    return TCL_OK;
}

static void
fixedImplFree (
    void *constraintData
................................................................................
static int
matchImpl (
    Tcl_Interp *interp,
    void *constraintData,
    char *text
    )
{
    if (Tcl_StringCaseMatch (text, Tcl_GetString ((Tcl_Obj *) constraintData), 0))
        return 1;
    return 0;
}

static int
matchNocaseImpl (
    Tcl_Interp *interp,
    void *constraintData,
    char *text
    )
{
    if (Tcl_StringCaseMatch (text, Tcl_GetString ((Tcl_Obj *) constraintData),
            TCL_MATCH_NOCASE))
        return 1;
    return 0;
}

static int
matchTCObjCmd (
    ClientData clientData,
................................................................................
    )
{
    SchemaData *sdata = GETASI;
    SchemaConstraint *sc;

    CHECK_TI
    CHECK_TOPLEVEL
    checkNrArgs (2,3,"Expected: ?-nocase? <match pattern>");
    if (objc == 3) {
        if (strcmp ("-nocase", Tcl_GetString (objv[1])) != 0) {
            SetResult ("Expected: ?-nocase? <match pattern>");
            return TCL_ERROR;
        }
        objv++;
    }
    ADD_CONSTRAINT (sdata, sc)
    if (objc == 2) {
        sc->constraint = matchImpl;
    } else {
        sc->constraint = matchNocaseImpl;
    }
    sc->freeData = matchImplFree;
    Tcl_IncrRefCount (objv[1]);
    sc->constraintData = objv[1];
    return TCL_OK;
}

static void
................................................................................
        /* A bce date */
        text++;
    }
    for (i = 0; i < 4; i++) {
        if (*text < '0' || *text > '9') return 0;
        text++;
    }
    while (*text >= '0' && *text <= '9') text++;
    if (*text != '-') return 0;
    y = atoi(text-4);
    /* There isn't a year 0. it's either 0001 or -0001 */
    if (y == 0) return 0;
    text++;
    for (i = 0; i < 2; i++) {
        if (*text < '0' || *text > '9') return 0;
................................................................................
    Tcl_Interp *interp
    )
{
    /* Inline definition commands. */
    Tcl_CreateObjCommand (interp, "tdom::schema::defelement",
                          schemaInstanceCmd, NULL, NULL);
    Tcl_CreateObjCommand (interp, "tdom::schema::defpattern",
                          schemaInstanceCmd, NULL, NULL);
    Tcl_CreateObjCommand (interp, "tdom::schema::deftext",
                          schemaInstanceCmd, NULL, NULL);
    Tcl_CreateObjCommand (interp, "tdom::schema::start",
                          schemaInstanceCmd, NULL, NULL);

    /* The "any" definition command. */
    Tcl_CreateObjCommand (interp, "tdom::schema::any",
                          AnyPatternObjCmd, NULL, NULL);

Changes to generic/schema.h.

102
103
104
105
106
107
108

109
110
111
112
113
114
115
...
117
118
119
120
121
122
123



124
125
126
127
128
129
130
    VALIDATION_STARTED,
    VALIDATION_ERROR,
    VALIDATION_FINISHED
} ValidationState;

typedef struct 
{

    char *start;
    char *startNamespace;
    Tcl_HashTable element;
    Tcl_HashTable namespace;
    Tcl_HashEntry *emptyNamespace;
    Tcl_HashTable pattern;
    Tcl_HashTable attrNames;
................................................................................
    SchemaCP **patternList; 
    unsigned int numPatternList;
    unsigned int patternListSize;
    unsigned int forwardPatternDefs;
    SchemaQuant *quants;
    unsigned int numQuants;
    unsigned int quantsSize;



    Tcl_Obj **evalStub;
    Tcl_Obj **textStub;
    char *currentNamespace;
    int   defineToplevel;
    int   isTextConstraint;
    int   isAttributeConstaint;
    SchemaCP *cp;






>







 







>
>
>







102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
    VALIDATION_STARTED,
    VALIDATION_ERROR,
    VALIDATION_FINISHED
} ValidationState;

typedef struct 
{
    Tcl_Obj *self;
    char *start;
    char *startNamespace;
    Tcl_HashTable element;
    Tcl_HashTable namespace;
    Tcl_HashEntry *emptyNamespace;
    Tcl_HashTable pattern;
    Tcl_HashTable attrNames;
................................................................................
    SchemaCP **patternList; 
    unsigned int numPatternList;
    unsigned int patternListSize;
    unsigned int forwardPatternDefs;
    SchemaQuant *quants;
    unsigned int numQuants;
    unsigned int quantsSize;
    int       currentEvals;
    int       cleanupAfterEval;
    Tcl_Obj  *reportCmd;
    Tcl_Obj **evalStub;
    Tcl_Obj **textStub;
    char *currentNamespace;
    int   defineToplevel;
    int   isTextConstraint;
    int   isAttributeConstaint;
    SchemaCP *cp;

Changes to generic/tclexpat.c.

2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
....
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
....
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
....
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
....
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
....
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
....
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
....
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
....
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
....
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
....
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
....
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
....
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
....
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
....
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
....
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
....
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
....
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
....
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
              cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->elementstartcommand);
              Tcl_IncrRefCount(cmdPtr);
              Tcl_Preserve((ClientData) expat->interp);

              Tcl_ListObjAppendElement(expat->interp, cmdPtr,
                                       Tcl_NewStringObj((char *)name, -1));
              Tcl_ListObjAppendElement(expat->interp, cmdPtr, atList);
#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
              result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
              result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                                     TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */

              Tcl_DecrRefCount(cmdPtr);
              Tcl_Release((ClientData) expat->interp);

              TclExpatHandlerResult(expat, activeTclHandlerSet, result);
          }
      }
................................................................................

              cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->elementendcommand);
              Tcl_IncrRefCount(cmdPtr);
              Tcl_Preserve((ClientData) expat->interp);

              Tcl_ListObjAppendElement(expat->interp, cmdPtr,
                                       Tcl_NewStringObj((char *)name, -1));
#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
              result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
              result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                                     TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT );
#endif /* TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */

              Tcl_DecrRefCount(cmdPtr);
              Tcl_Release((ClientData) expat->interp);

              TclExpatHandlerResult(expat, activeTclHandlerSet, result);
          }
      }
................................................................................
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);

      Tcl_ListObjAppendElement(expat->interp, cmdPtr,
                               Tcl_NewStringObj((char *)prefix, -1));
      Tcl_ListObjAppendElement(expat->interp, cmdPtr,
                               Tcl_NewStringObj((char *)uri,    -1));
#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
      result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */

      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
       */

      cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->endnsdeclcommand);
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);

      Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewStringObj((char *)prefix, -1));
#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
      result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */

      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
           */
          cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->datacommand);
          Tcl_IncrRefCount(cmdPtr);
          Tcl_Preserve((ClientData) expat->interp);

          Tcl_ListObjAppendElement(expat->interp, cmdPtr,
                                   Tcl_NewStringObj((char *)s, len));
#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
          result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
          result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                                 TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */

          Tcl_DecrRefCount(cmdPtr);
          Tcl_Release((ClientData) expat->interp);

          TclExpatHandlerResult(expat, activeTclHandlerSet, result);
      }
  nextTcl:
................................................................................

      cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->picommand);
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);

      Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewStringObj((char *)target, strlen(target)));
      Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewStringObj((char *)data, strlen(data)));
#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
      result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */

      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
       */

      cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->defaultcommand);
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);

      Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewStringObj((char *)s, len));
#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
      result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */

      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
          Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewStringObj((char *)publicId, strlen(publicId)));
      }
      if (notationName == NULL) {
          Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewListObj(0, NULL));
      } else {
          Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewStringObj((char *)notationName, strlen(notationName)));
      }
#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
      result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
      result = Tcl_EvalObjEx(expat->interp, cmdPtr,
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */

      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
          Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewStringObj((char *)systemId, strlen(systemId)));
      }
      if (publicId == NULL) {
          Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewListObj(0, NULL));
      } else {
          Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewStringObj((char *)publicId, strlen(publicId)));
      }
#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
      result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */

      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
          Tcl_ListObjAppendElement(expat->interp, cmdPtr,
	      Tcl_NewStringObj((char *)publicId, strlen(publicId)));
      } else {
          Tcl_ListObjAppendElement(expat->interp, cmdPtr,
	      Tcl_NewStringObj("", 0));
      }

#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
      result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */

      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      switch (result) {
      case TCL_OK:
          break;
................................................................................
      cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->commentCommand);
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);

      Tcl_ListObjAppendElement(expat->interp, cmdPtr,
                               Tcl_NewStringObj((char *)data, strlen(data)));

#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
      result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */

      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
          goto nextTcl;
      }

      cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->notStandaloneCommand);
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);

#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
      result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */

      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
          goto nextTcl;
      }

      cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->startCdataSectionCommand);
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);

#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
      result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */

      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
          goto nextTcl;
      }

      cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->endCdataSectionCommand);
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);

#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
      result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */

      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................


      content = Tcl_NewListObj (0, NULL);
      generateModel (expat->interp, content, model);

      Tcl_ListObjAppendElement(expat->interp, cmdPtr, content);

#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
      result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */

      Tcl_DecrRefCount(cmdPtr);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
  }
................................................................................
      else {
          Tcl_ListObjAppendElement (expat->interp, cmdPtr,
                                    Tcl_NewStringObj ((char*)dflt, strlen (dflt)));
      }
      Tcl_ListObjAppendElement (expat->interp, cmdPtr,
                                Tcl_NewIntObj (isrequired));

#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
      result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */
      
      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
      } else {
          Tcl_ListObjAppendElement(expat->interp, cmdPtr,
                               Tcl_NewStringObj("NULL", 4));
      }
      Tcl_ListObjAppendElement(expat->interp, cmdPtr,
                           Tcl_NewIntObj(has_internal_subset));

#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
      result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */
      
      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
          goto nextTcl;
      }

      cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->endDoctypeDeclCommand);
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);

#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
      result = Tcl_GlobalEvalObj(expat->interp, cmdPtr);
#else
      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */
      
      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
                                    Tcl_NewStringObj ("", 0));
      }
      else  {
          Tcl_ListObjAppendElement (expat->interp, cmdPtr,
                                    Tcl_NewBooleanObj (standalone));
      }

#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0)
      result = Tcl_GlobalEvalObj (expat->interp, cmdPtr);
#else
      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
#endif /* TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0 */
      
      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult (expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;






<
<
<

|
<







 







<
<
<


<







 







<
<
<


<







 







<
<
<


<







 







<
<
<


<







 







<
<
<


<







 







<
<
<


<







 







<
<
<


<







 







<
<
<


<







 







<
<
<


<







 







<
<
<


<







 







<
<
<


<







 







<
<
<


<







 







<
<
<


<







 







<
<
<


<







 







<
<
<


<







 







<
<
<


<







 







<
<
<


<







 







<
<
<


<







2263
2264
2265
2266
2267
2268
2269



2270
2271

2272
2273
2274
2275
2276
2277
2278
....
2393
2394
2395
2396
2397
2398
2399



2400
2401

2402
2403
2404
2405
2406
2407
2408
....
2491
2492
2493
2494
2495
2496
2497



2498
2499

2500
2501
2502
2503
2504
2505
2506
....
2571
2572
2573
2574
2575
2576
2577



2578
2579

2580
2581
2582
2583
2584
2585
2586
....
2744
2745
2746
2747
2748
2749
2750



2751
2752

2753
2754
2755
2756
2757
2758
2759
....
2843
2844
2845
2846
2847
2848
2849



2850
2851

2852
2853
2854
2855
2856
2857
2858
....
2924
2925
2926
2927
2928
2929
2930



2931
2932

2933
2934
2935
2936
2937
2938
2939
....
3040
3041
3042
3043
3044
3045
3046



3047
3048

3049
3050
3051
3052
3053
3054
3055
....
3135
3136
3137
3138
3139
3140
3141



3142
3143

3144
3145
3146
3147
3148
3149
3150
....
3294
3295
3296
3297
3298
3299
3300



3301
3302

3303
3304
3305
3306
3307
3308
3309
....
3580
3581
3582
3583
3584
3585
3586



3587
3588

3589
3590
3591
3592
3593
3594
3595
....
3655
3656
3657
3658
3659
3660
3661



3662
3663

3664
3665
3666
3667
3668
3669
3670
....
3731
3732
3733
3734
3735
3736
3737



3738
3739

3740
3741
3742
3743
3744
3745
3746
....
3804
3805
3806
3807
3808
3809
3810



3811
3812

3813
3814
3815
3816
3817
3818
3819
....
3961
3962
3963
3964
3965
3966
3967



3968
3969

3970
3971
3972
3973
3974
3975
3976
....
4058
4059
4060
4061
4062
4063
4064



4065
4066

4067
4068
4069
4070
4071
4072
4073
....
4157
4158
4159
4160
4161
4162
4163



4164
4165

4166
4167
4168
4169
4170
4171
4172
....
4234
4235
4236
4237
4238
4239
4240



4241
4242

4243
4244
4245
4246
4247
4248
4249
....
4332
4333
4334
4335
4336
4337
4338



4339
4340

4341
4342
4343
4344
4345
4346
4347
              cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->elementstartcommand);
              Tcl_IncrRefCount(cmdPtr);
              Tcl_Preserve((ClientData) expat->interp);

              Tcl_ListObjAppendElement(expat->interp, cmdPtr,
                                       Tcl_NewStringObj((char *)name, -1));
              Tcl_ListObjAppendElement(expat->interp, cmdPtr, atList);



              result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                                     TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT );


              Tcl_DecrRefCount(cmdPtr);
              Tcl_Release((ClientData) expat->interp);

              TclExpatHandlerResult(expat, activeTclHandlerSet, result);
          }
      }
................................................................................

              cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->elementendcommand);
              Tcl_IncrRefCount(cmdPtr);
              Tcl_Preserve((ClientData) expat->interp);

              Tcl_ListObjAppendElement(expat->interp, cmdPtr,
                                       Tcl_NewStringObj((char *)name, -1));



              result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                                     TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT );


              Tcl_DecrRefCount(cmdPtr);
              Tcl_Release((ClientData) expat->interp);

              TclExpatHandlerResult(expat, activeTclHandlerSet, result);
          }
      }
................................................................................
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);

      Tcl_ListObjAppendElement(expat->interp, cmdPtr,
                               Tcl_NewStringObj((char *)prefix, -1));
      Tcl_ListObjAppendElement(expat->interp, cmdPtr,
                               Tcl_NewStringObj((char *)uri,    -1));



      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);


      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
       */

      cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->endnsdeclcommand);
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);

      Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewStringObj((char *)prefix, -1));



      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);


      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
           */
          cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->datacommand);
          Tcl_IncrRefCount(cmdPtr);
          Tcl_Preserve((ClientData) expat->interp);

          Tcl_ListObjAppendElement(expat->interp, cmdPtr,
                                   Tcl_NewStringObj((char *)s, len));



          result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                                 TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);


          Tcl_DecrRefCount(cmdPtr);
          Tcl_Release((ClientData) expat->interp);

          TclExpatHandlerResult(expat, activeTclHandlerSet, result);
      }
  nextTcl:
................................................................................

      cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->picommand);
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);

      Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewStringObj((char *)target, strlen(target)));
      Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewStringObj((char *)data, strlen(data)));



      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);


      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
       */

      cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->defaultcommand);
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);

      Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewStringObj((char *)s, len));



      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);


      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
          Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewStringObj((char *)publicId, strlen(publicId)));
      }
      if (notationName == NULL) {
          Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewListObj(0, NULL));
      } else {
          Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewStringObj((char *)notationName, strlen(notationName)));
      }



      result = Tcl_EvalObjEx(expat->interp, cmdPtr,
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);


      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
          Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewStringObj((char *)systemId, strlen(systemId)));
      }
      if (publicId == NULL) {
          Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewListObj(0, NULL));
      } else {
          Tcl_ListObjAppendElement(expat->interp, cmdPtr, Tcl_NewStringObj((char *)publicId, strlen(publicId)));
      }



      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);


      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
          Tcl_ListObjAppendElement(expat->interp, cmdPtr,
	      Tcl_NewStringObj((char *)publicId, strlen(publicId)));
      } else {
          Tcl_ListObjAppendElement(expat->interp, cmdPtr,
	      Tcl_NewStringObj("", 0));
      }




      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);


      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      switch (result) {
      case TCL_OK:
          break;
................................................................................
      cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->commentCommand);
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);

      Tcl_ListObjAppendElement(expat->interp, cmdPtr,
                               Tcl_NewStringObj((char *)data, strlen(data)));




      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);


      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
          goto nextTcl;
      }

      cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->notStandaloneCommand);
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);




      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);


      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
          goto nextTcl;
      }

      cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->startCdataSectionCommand);
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);




      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);


      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
          goto nextTcl;
      }

      cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->endCdataSectionCommand);
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);




      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);


      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................


      content = Tcl_NewListObj (0, NULL);
      generateModel (expat->interp, content, model);

      Tcl_ListObjAppendElement(expat->interp, cmdPtr, content);




      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);


      Tcl_DecrRefCount(cmdPtr);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
  }
................................................................................
      else {
          Tcl_ListObjAppendElement (expat->interp, cmdPtr,
                                    Tcl_NewStringObj ((char*)dflt, strlen (dflt)));
      }
      Tcl_ListObjAppendElement (expat->interp, cmdPtr,
                                Tcl_NewIntObj (isrequired));




      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);

      
      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
      } else {
          Tcl_ListObjAppendElement(expat->interp, cmdPtr,
                               Tcl_NewStringObj("NULL", 4));
      }
      Tcl_ListObjAppendElement(expat->interp, cmdPtr,
                           Tcl_NewIntObj(has_internal_subset));




      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);

      
      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
          goto nextTcl;
      }

      cmdPtr = Tcl_DuplicateObj(activeTclHandlerSet->endDoctypeDeclCommand);
      Tcl_IncrRefCount(cmdPtr);
      Tcl_Preserve((ClientData) expat->interp);




      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);

      
      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult(expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;
................................................................................
                                    Tcl_NewStringObj ("", 0));
      }
      else  {
          Tcl_ListObjAppendElement (expat->interp, cmdPtr,
                                    Tcl_NewBooleanObj (standalone));
      }




      result = Tcl_EvalObjEx(expat->interp, cmdPtr, 
                             TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);

      
      Tcl_DecrRefCount(cmdPtr);
      Tcl_Release((ClientData) expat->interp);

      TclExpatHandlerResult (expat, activeTclHandlerSet, result);
  nextTcl:
      activeTclHandlerSet = activeTclHandlerSet->nextHandlerSet;

Changes to tests/schema.test.

290
291
292
293
294
295
296

































































































297
298
299
300
301
302
303
...
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
...
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
...
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
...
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
....
2570
2571
2572
2573
2574
2575
2576

























2577
2578
2579
2580
2581
2582
2583
....
2936
2937
2938
2939
2940
2941
2942











































































































2943
2944
2945
2946
2947
2948
2949
....
3480
3481
3482
3483
3484
3485
3486
3487





3488
























            element s1b *
            element s1c
        }
    }} errMsg]
    s1 delete
    set result
} 1


































































































test schema-2.1 {grammar definition: ref} {
    tdom::schema create grammar
    grammar defpattern thisPattern {
        element a
        element b
    }
................................................................................
            group 2 {
                element e1
                element e2
            }
            element e2 *
        }
        foreach e {e1 e2} {
            grammar defelement $e {}
        }
    }
    dom parse -validateCmd grammar {
        <doc><e1/><e1/><e2/><e1/><e2/><e2/><e2/><e2/></doc>
    } doc
    $doc delete
    grammar delete
................................................................................
                    element e2
                }
                element e2
            }
            element e2 *
        }
        foreach e {e1 e2} {
            grammar defelement $e {}
        }
    }
    dom parse -validateCmd grammar {
        <doc><e1/><e1><e2/></e1><e2/><e1><e2/></e1><e2/><e2/><e2/><e2/></doc>
    } doc
    $doc delete
    grammar delete
................................................................................
                element e1 1 {
                    element e2
                }
                element e2
            }
        }
        foreach e {e1 e2} {
            grammar defelement $e {}
        }
    }
    dom parse -validateCmd grammar {
        <doc><e1/><e1><e2/></e1><e2/></doc>
    } doc
    $doc delete
    grammar delete
................................................................................
                element e1 1 {
                    element e2
                }
                element e2
            }
        }
        foreach e {e1 e2} {
            grammar defelement $e {}
        }
    }
    ::xml::parser p -validateCmd grammar
    p parse {
        <doc><e1/><e1><e2/></e1><e2/></doc>
    }
    p delete
................................................................................
        {<doc><e>a1!/</e></doc>}
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {1 1 1 0 1 0}


























test schema-14.7 {text: regexp} {
    tdom::schema s
    s define {
        defelement doc {
            element e *
        }
................................................................................
            $doc delete
        }
        lappend result $rc
    }
    s delete
    set result
} {0 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 1 0}












































































































test schema-15.1 {constraint cmd tcl} {
    tdom::schema s
    s define {
        defelement a {
            tcl append ::schema-15.1
            element b
................................................................................
        <doc>12</doc>
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 1 0 1 0 1 1 0}






}






























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







|







 







|







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 








>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
...
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
...
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
...
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
...
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
....
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
....
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
....
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
            element s1b *
            element s1c
        }
    }} errMsg]
    s1 delete
    set result
} 1

test schema-1.18 {delete schema cmd in definition script} {
    tdom::schema create s
    s define {
        defelement e {
            s delete
            element e1 1 {
                set ::result [catch {s delete}]
            }
        }
    }
    lappend result [info commands s]
} {1 {}}

test schema-1.19 {call top level schema cmd in definition script} {
    tdom::schema create s
    set result [catch {s define {
        defelement e {
            element e1 1 {
                deftext foo {minLength 1}
                defelement bar {}
            }
            element bar
        }
    }}]
    lappend result [info commands s]
    s delete
    set result
} {1 s}

test schema-1.20 {call top level schema cmd in definition script} {
    tdom::schema create s
    set result [catch {s defelement e {
            element e1 1 {
                deftext foo {minLength 1}
                defelement bar {}
            }
            element bar
        }
    }]
    lappend result [info commands s]
    s delete
    set result
} {1 s}

test schema-1.21 {Create other schema cmd in definition script} {
    tdom::schema create s1
    s1 defelement e {
        element e1 1 {}
        element e1 1 {
            ::tdom::schema create ::s2
            ::s2 define {
                defelement s2 {
                    element s2e
                    element s2ee
                }
                foreach e {s2e s2ee} {
                    defelement $e {text}
                }
            }
        }
    }
    set result [info commands s1]
    lappend result [info commands s2]
    foreach xml {
        <e><e1/><e1/></e>
        <s2><s2e>foo</s2e><s2ee/></s2>
    } {
        lappend result [s1 validate $xml]
        lappend result [s2 validate $xml]
    }
    s2 delete
    s1 delete
    set result
} {s1 s2 1 0 0 1}

test schema-1.22 {Call not toplevel cmd methods in definition script} {
    tdom::schema create s
    set result [list]
    s define {
        defelement e {
            lappend ::result [s nrForwardDefinitions]
            element e1
            lappend ::result [s nrForwardDefinitions]
            element e1
            lappend ::result [s nrForwardDefinitions]
            element e2
            lappend ::result [s nrForwardDefinitions]
        }
        foreach e {e1 e2} {
            defelement $e {text}
            lappend ::result [s nrForwardDefinitions]
        }
    }
    s delete
    set result
} {0 1 1 2 1 0}

test schema-2.1 {grammar definition: ref} {
    tdom::schema create grammar
    grammar defpattern thisPattern {
        element a
        element b
    }
................................................................................
            group 2 {
                element e1
                element e2
            }
            element e2 *
        }
        foreach e {e1 e2} {
            defelement $e {}
        }
    }
    dom parse -validateCmd grammar {
        <doc><e1/><e1/><e2/><e1/><e2/><e2/><e2/><e2/></doc>
    } doc
    $doc delete
    grammar delete
................................................................................
                    element e2
                }
                element e2
            }
            element e2 *
        }
        foreach e {e1 e2} {
            defelement $e {}
        }
    }
    dom parse -validateCmd grammar {
        <doc><e1/><e1><e2/></e1><e2/><e1><e2/></e1><e2/><e2/><e2/><e2/></doc>
    } doc
    $doc delete
    grammar delete
................................................................................
                element e1 1 {
                    element e2
                }
                element e2
            }
        }
        foreach e {e1 e2} {
            defelement $e {}
        }
    }
    dom parse -validateCmd grammar {
        <doc><e1/><e1><e2/></e1><e2/></doc>
    } doc
    $doc delete
    grammar delete
................................................................................
                element e1 1 {
                    element e2
                }
                element e2
            }
        }
        foreach e {e1 e2} {
            defelement $e {}
        }
    }
    ::xml::parser p -validateCmd grammar
    p parse {
        <doc><e1/><e1><e2/></e1><e2/></doc>
    }
    p delete
................................................................................
        {<doc><e>a1!/</e></doc>}
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {1 1 1 0 1 0}

test schema-14.6a {text: match (glob style) -nocase} {
    tdom::schema s
    s define {
        defelement doc {
            element e *
        }
        defelement e {
            text {match -nocase {[A-Z]*1[_!]}}
        }
    }
    set result [list]
    foreach xml {
        <doc/>
        {<doc><e>disabled1_</e></doc>}
        {<doc><e>dis able1_</e></doc>}
        {<doc><e>something</e></doc>}
        {<doc><e>a1!</e></doc>}
        {<doc><e>a1!/</e></doc>}
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {1 1 1 0 1 0}

test schema-14.7 {text: regexp} {
    tdom::schema s
    s define {
        defelement doc {
            element e *
        }
................................................................................
            $doc delete
        }
        lappend result $rc
    }
    s delete
    set result
} {0 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 1 0}

test schema-14.19 {deftext} {
    tdom::schema s
    s deftext len2-4 {
        minLength 2
        maxLength 4
    }
    s defelement doc {
        element e
    }
    s defelement e {
        attribute this type len2-4
        attribute foo ? type len2-4
    }
    set result [list]
    foreach xml {
        <doc><e/></doc>
        {<doc><e foo="bar"/></doc>}
        {<doc><e this="bar"/></doc>}
        {<doc><e this=""/></doc>}
        {<doc><e this="12" foo="bar"/></doc>}
        {<doc><e this="12" foo="b"/></doc>}
        {<doc><e this="1234"/></doc>}
        {<doc><e this="12345"/></doc>}
        {<doc><e this="12345alkajsdlfjkals" and="this"/></doc>}
        {<doc><e and="this" this="12345alkajsdlfjkals"/></doc>}
    } {
        lappend result [s validate $xml errMsg]
        set rc [catch {dom parse -validateCmd s $xml doc}]
        if {$rc == 0} {
            $doc delete
        }
        lappend result $rc
    }
    s delete
    set result
} {0 1 0 1 1 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1}

test schema-14.19a {deftext} {
    tdom::schema s
    s deftext len2-4 {
        minLength 2
        maxLength 4
    }
    s defelement doc {
        element e ! {
            attribute this type len2-4
            attribute foo ? type len2-4
        }
    }
    set result [list]
    foreach xml {
        <doc><e/></doc>
        {<doc><e foo="bar"/></doc>}
        {<doc><e this="bar"/></doc>}
        {<doc><e this=""/></doc>}
        {<doc><e this="12" foo="bar"/></doc>}
        {<doc><e this="12" foo="b"/></doc>}
        {<doc><e this="1234"/></doc>}
        {<doc><e this="12345"/></doc>}
        {<doc><e this="12345alkajsdlfjkals" and="this"/></doc>}
        {<doc><e and="this" this="12345alkajsdlfjkals"/></doc>}
    } {
        lappend result [s validate $xml]
        set rc [catch {dom parse -validateCmd s $xml doc}]
        if {$rc == 0} {
            $doc delete
        }
        lappend result $rc
    }
    s delete
    set result
} {0 1 0 1 1 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1}

test schema-14.20 {deftext} {
    tdom::schema s
    s deftext len2-4 {
        minLength 2
        maxLength 4
    }
    s defelement doc {
        element e ! {
            nsattribute this http://tdom.org/test {
                minLength 2
                maxLength 4
            }
            nsattribute foo http://tdom.org/test ? type len2-4
        }
    }
    set result [list]
    foreach xml {
        <doc><e/></doc>
        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:foo="bar"/></doc>}
        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:this="bar"/></doc>}
        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:this=""/></doc>}
        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:this="12" ns1:foo="bar"/></doc>}
        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:this="12" ns1:foo="b"/></doc>}
        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:this="1234"/></doc>}
        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:this="12345"/></doc>}
        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:this="12345alkajsdlfjkals" ns1:and="this"/></doc>}
        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:and="this" ns1:this="12345alkajsdlfjkals"/></doc>}
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 0 1 0 1 0 1 0 0 0}

test schema-15.1 {constraint cmd tcl} {
    tdom::schema s
    s define {
        defelement a {
            tcl append ::schema-15.1
            element b
................................................................................
        <doc>12</doc>
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 1 0 1 0 1 1 0}

test schema-17.1 {info} {
    tdom::schema s
    s define {
        foreach e {a b1 b11 b2 c} {
            defelement $e {}
        }
    }
    set result [lsort [s info defelements]]
    s delete
    set result
} {a b1 b11 b2 c}

test schema-17.2 {info} {
    tdom::schema s
    s define {
        defelement b {
            element b1
            element b2
        }
        defelement a {
            element a1
            element a2
        }
    }
    set result [lsort [s info defelements]]
    s delete
    set result
} {a b}

}