tDOM

Check-in [fa18fb363f]
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:Added a -nocase flag to the text constraint command match (because it was easy). Small modification to the text constraint command isodate. It now accept years longer that four digits (as the xsd date types do). Added some more documentation.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | schema
Files: files | file ages | folders
SHA3-256: fa18fb363f1194d7b5daf9170e5e015969e868bc5c22df5e0cc19383f9352c2a
User & Date: rolf 2019-03-01 11:58:59
Context
2019-03-02
02:28
Removed #define and code for a tcl version (8.0) that isn't support for a long time. check-in: 0efaef90de user: rolf tags: schema
2019-03-01
11:58
Added a -nocase flag to the text constraint command match (because it was easy). Small modification to the text constraint command isodate. It now accept years longer that four digits (as the xsd date types do). Added some more documentation. check-in: fa18fb363f user: rolf tags: schema
2019-02-28
01:31
Added attribute value constraining with text types. check-in: 44ebaf2b3f user: rolf tags: schema
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
...
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
...
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
      <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).
        With <m>constraint script</m> argument a text matching this

        script 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>?</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.

3206
3207
3208
3209
3210
3211
3212












3213

3214
3215
3216
3217
3218
3219
3220
....
3224
3225
3226
3227
3228
3229
3230



3231




3232

3233



3234
3235
3236
3237
3238
3239
3240
....
3494
3495
3496
3497
3498
3499
3500

3501
3502
3503
3504
3505
3506
3507
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;






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







 







>
>
>
|
>
>
>
>

>
|
>
>
>







 







>







3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
....
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
....
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
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;

Changes to tests/schema.test.

2554
2555
2556
2557
2558
2559
2560

























2561
2562
2563
2564
2565
2566
2567
    s define {
        defelement doc {
            element e *
        }
        defelement e {
            text {match {[a-zA-Z]*1[_!]}}
        }

























    }
    set result [list]
    foreach xml {
        <doc/>
        {<doc><e>disabled1_</e></doc>}
        {<doc><e>dis able1_</e></doc>}
        {<doc><e>something</e></doc>}






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







2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
    s define {
        defelement doc {
            element e *
        }
        defelement e {
            text {match {[a-zA-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.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>}