Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Merged from schema. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | mixedoptimization |
Files: | files | file ages | folders |
SHA3-256: |
01080e891e330329304f90a5dbd5c90e |
User & Date: | rolf 2020-01-27 23:48:14.797 |
Context
2020-02-01
| ||
01:12 | Added a configurable threshold for the optimization. Closed-Leaf check-in: 3ae775c452 user: rolf tags: mixedoptimization | |
2020-01-27
| ||
23:48 | Merged from schema. check-in: 01080e891e user: rolf tags: mixedoptimization | |
2020-01-21
| ||
00:57 | Added the schema definition command associate and the requesting method info stack associated, tests and doc. check-in: 254c84e47d user: rolf tags: schema | |
2020-01-20
| ||
00:17 | Merged from schema. check-in: 25933a5ac2 user: rolf tags: mixedoptimization | |
Changes
Changes to doc/schema.html.
1 2 3 4 5 6 | <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"> | | | | | | 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 | <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="#SECTid0x5589be9ed630">NAME</a> · <a href="#SECTid0x5589be942120">SYNOPSIS</a> · <a href="#SECTid0x5589be9cb810">DESCRIPTION </a> · <a href="#SECTid0x5589bea2daf0">Schema definition scripts</a> · <a href="#SECTid0x5589bea39a30">Quantity specifier</a> · <a href="#SECTid0x5589bea3b880">Text constraint scripts</a> · <a href="#SECTid0x5589bea49900">Local key constraints</a> · <a href="#SECTid0x5589bea4b710">Exampels</a> · <a href="#SECTid0x5589bea4d6c0">KEYWORDS</a> </div><hr class="navsep"> </div><div class="body"> <h2><a name="SECTid0x5589be9ed630">NAME</a></h2><p class="namesection"> <b class="names">tdom::schema - </b><br>Create a schema validation command</p> <h2><a name="SECTid0x5589be942120">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="SECTid0x5589be9cb810">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 data or to post-validate a tDOM DOM tree (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"> |
︙ | ︙ | |||
166 167 168 169 170 171 172 | <dt> <b>text</b> <i>text</i> </dt> <dd>Checks if the current validation state allows the given text content. It raises error, if not.</dd> | > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | <dt> <b>text</b> <i>text</i> </dt> <dd>Checks if the current validation state allows the given text content. It raises error, if not.</dd> </dl> </dd> <dt> <b class="method">stack</b> <i class="m">(top|inside|associated)</i> </dt> <dd>In Tcl scripts evaluated by validation this method provides information about the current validation stack. Called outside this context the method returns the empty string. <dl class="optlist"> <dt><b>top</b></dt> <dd>Returns the element which content is currently checked (the at the moment open element tag). </dd> <dt><b>inside</b></dt> <dd>Returns all currently open elements as a list.</dd> <dt><b>associated</b></dt> <dd>Returns the data associated with the current top most stack content particle or the empty string it there isn't. </dd> </dl> </dd> <dt> <b class="method">validate</b> <i class="m"><XML string></i> <i class="m">?objVar?</i> </dt> <dd>Returns true if the <i class="m"><XML string></i> is valid or false otherwise. If validation failed and the optional <i class="m">objVar</i> argument is given, then the variable with that |
︙ | ︙ | |||
198 199 200 201 202 203 204 205 206 207 208 209 210 211 | and the optional <i class="m">objVar</i> argument is given, then the variable with that name is set to a validation error message. If the XML string is valid and the optional <i class="m">objVar</i> argument is given, then the variable with that name is set to the empty string.</dd> <dt> <b class="method">domvalidate</b> <i class="m">domNode</i> <i class="m">?objVar?</i> </dt> <dd>Returns true if the first argument is a valid tree or false otherwise. If validation failed and the optional <i class="m">objVar</i> argument is given, then the variable with that | > > > > > > > > > > > > > > > | 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 | and the optional <i class="m">objVar</i> argument is given, then the variable with that name is set to a validation error message. If the XML string is valid and the optional <i class="m">objVar</i> argument is given, then the variable with that name is set to the empty string.</dd> <dt> <b class="method">validatechannel</b> <i class="m">channel</i> <i class="m">?objVar?</i> </dt> <dd>Returns true if the content read ouf of the tcl channel <i class="m">channel</i> is valid or false otherwise. Since data read out of a tcl channel is UTF-8 encoded any misleading encoding declaration at the beginning of the data will lead to errors. If the validation failed and the optional <i class="m">objVar</i> argument is given, then the variable with that name is set to a validation error message. If the XML string is valid and the optional <i class="m">objVar</i> argument is given, then the variable with that name is set to the empty string.</dd> <dt> <b class="method">domvalidate</b> <i class="m">domNode</i> <i class="m">?objVar?</i> </dt> <dd>Returns true if the first argument is a valid tree or false otherwise. If validation failed and the optional <i class="m">objVar</i> argument is given, then the variable with that |
︙ | ︙ | |||
361 362 363 364 365 366 367 | <dt><b class="method">reset</b></dt> <dd>This method resets the validation command into state READY (while preserving the defined grammer).</dd> </dl> | | | 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | <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="SECTid0x5589bea2daf0">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 qualify the content as valid. It is a validation error if there is additional (not matched) content.</p><p>The schema definition commands are:</p><dl class="commandlist"> |
︙ | ︙ | |||
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 | <dd>Evaluates the Tcl script <i class="m">tclcmd arg arg ... </i> and the schema command appended to the argument list. This validation command is only allowed in strict sequential context (not in choice, mixed and interleave). If the return code is something else than 0 (TCL_OK) then this ia a validation error.</dd> <dt> <b class="method">prefixns</b> <i class="m">?prefixUriList?</i> </dt> <dd>This defines a prefix to namespace URI mapping exactly as a <i>schemacmd prefixns</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">defelement</b> <i class="m">name</i> <i class="m">?namespace?</i> <i class="m"><definition script></i> </dt> | > > > > > > > > > > > > > | > > > > > > > > > > > | 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 | <dd>Evaluates the Tcl script <i class="m">tclcmd arg arg ... </i> and the schema command appended to the argument list. This validation command is only allowed in strict sequential context (not in choice, mixed and interleave). If the return code is something else than 0 (TCL_OK) then this ia a validation error.</dd> <dt> <b class="method">associate</b> <i class="m">data</i> </dt> <dd>This command is only allowed top-level inside the definition scripts of the element, elementtype, pattern or interleave content particle. Associate the as argument given <i class="m">data</i> with the currently defined content particle and may be requested in scripts evaluated while validating the content of that particle with the schema command method call <i class="m">info stack associated</i>.</dd> <dt> <b class="method">prefixns</b> <i class="m">?prefixUriList?</i> </dt> <dd>This defines a prefix to namespace URI mapping exactly as a <i>schemacmd prefixns</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">defelement</b> <i class="m">name</i> <i class="m">?namespace?</i> <i class="m"><definition script></i> </dt> <dd>This defines an element 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">defelementtype</b> <i class="m">name</i> <i class="m">?namespace?</i> <i class="m"><definition script></i> </dt> <dd>This defines an elementtype exactly as a <i>schemacmd defelementtype</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"><definition script></i> </dt> <dd>This defines a named pattern exactly as a <i>schemacmd defpattern</i> call. This is meant as toplevel command of a |
︙ | ︙ | |||
568 569 570 571 572 573 574 | 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> | | | 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 | 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="SECTid0x5589bea39a30">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.</dd> |
︙ | ︙ | |||
612 613 614 615 616 617 618 | 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 >= 0 and n < 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> | | | 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 | 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 >= 0 and n < 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="SECTid0x5589bea3b880">Text constraint scripts</a></h2><p>Text - parsed character data, as XML calles it - must sometimes be of a certain kind, must comply to some rules etc to be valid. The text constraint script arguments to the text, attribute, nsattribute and deftext commands allow the following text constraint commands to check text for certain properties.</p><p>The text constraint commands are:</p><dl class="commandlist"> <dt> <b class="cmd">integer</b> <i class="m">?(xsd|tcl)?</i> |
︙ | ︙ | |||
915 916 917 918 919 920 921 | <dd>This text constraint match if the text value is a xsd:unsignedLong. This is an integer between 0 and 18446744073709551615, both included, optionally preceded by a + sign and leading zeros.</dd> </dl> | | | 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 | <dd>This text constraint match if the text value is a xsd:unsignedLong. This is an integer between 0 and 18446744073709551615, both included, optionally preceded by a + sign and leading zeros.</dd> </dl> <h2><a name="SECTid0x5589bea49900">Local key constraints</a></h2><p>Document wide uniqueness and foreign key constraints are available with the text constraint commands id and idref. Keyspaces allow for sub-tree local uniqueness and foreign key constraints.</p><dl class="commandlist"> <dt> <b class="cmd">keyspace</b> <i class="m"><names list></i> <i class="m"><constraint script></i> </dt> |
︙ | ︙ | |||
951 952 953 954 955 956 957 | active always matches. If the keyspace is active then reports error if there is still no key as the value at the end of the keyspace <i class="m"><name></i>. Otherwise it matches.</dd> </dl> | | | 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | active always matches. If the keyspace is active then reports error if there is still no key as the value at the end of the keyspace <i class="m"><name></i>. Otherwise it matches.</dd> </dl> <h2><a name="SECTid0x5589bea4b710">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"> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:annotation> <xsd:documentation xml:lang="en"> Purchase order schema for Example.com. |
︙ | ︙ | |||
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 | } foreach e {name email} { defelement $e {text} } } </pre> </div><hr class="navsep"><div class="navbar" align="center"> <a class="navaid" href="index.html">Contents</a> · <a class="navaid" href="category-index.html">Index</a> · <a class="navaid" href="keyword-index.html">Keywords</a> · <a class="navaid" href="http://tdom.org">Repository</a> </div> </body> </html> | > > > > | 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 | } foreach e {name email} { defelement $e {text} } } </pre> <h2><a name="SECTid0x5589bea4d6c0">KEYWORDS</a></h2><p class="keywords"> <a class="keyword" href="keyword-index.html#KW-Validation">Validation</a>, <a class="keyword" href="keyword-index.html#KW-Postvalidation">Postvalidation</a>, <a class="keyword" href="keyword-index.html#KW-DOM">DOM</a>, <a class="keyword" href="keyword-index.html#KW-SAX">SAX</a> </p> </div><hr class="navsep"><div class="navbar" align="center"> <a class="navaid" href="index.html">Contents</a> · <a class="navaid" href="category-index.html">Index</a> · <a class="navaid" href="keyword-index.html">Keywords</a> · <a class="navaid" href="http://tdom.org">Repository</a> </div> </body> </html> |
Changes to doc/schema.n.
︙ | ︙ | |||
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 | Checks if the current innermost open element may end here in the current state without violate validation constrains. It raises error, if not. .IP "\fBtext \fItext\fP\fR" Checks if the current validation state allows the given text content. It raises error, if not. .RE .TP \&\fB\fBvalidate\fP \fI<XML string>\fB \fI?objVar?\fB \&\fRReturns true if the \fI<XML string>\fR is valid or false otherwise. If validation failed and the optional \&\fIobjVar\fR argument is given, then the variable with that name is set to a validation error message. If the XML string is valid and the optional \fIobjVar\fR argument is given, then the variable with that name is set to the empty string. .TP \&\fB\fBvalidatefile\fP \fIfilename\fB \fI?objVar?\fB \&\fRReturns true if the content of \fIfilename\fR is valid or false otherwise. The given file is feeded as binary stream to expat, therefor only US-ASCII, ISO-8859-1, UTF-8 or UTF-16 encoded data will work with this method. If validation failed and the optional \fIobjVar\fR argument is given, then the variable with that name is set to a validation error message. If the XML string is valid and the optional \fIobjVar\fR argument is given, then the variable with that name is set to the empty string. .TP \&\fB\fBdomvalidate\fP \fIdomNode\fB \fI?objVar?\fB \&\fRReturns true if the first argument is a valid tree or false otherwise. If validation failed and the optional \&\fIobjVar\fR argument is given, then the variable with that name is set to a validation error message. If the dom tree is valid and the optional \fIobjVar\fR argument is given, then | > > > > > > > > > > > > > > > > > > > > > > > > > > > | 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | Checks if the current innermost open element may end here in the current state without violate validation constrains. It raises error, if not. .IP "\fBtext \fItext\fP\fR" Checks if the current validation state allows the given text content. It raises error, if not. .RE .TP \&\fB\fBstack\fP \fI(top|inside|associated)\fB \&\fRIn Tcl scripts evaluated by validation this method provides information about the current validation stack. Called outside this context the method returns the empty string. .RS .IP "\fBtop\fR" Returns the element which content is currently checked (the at the moment open element tag). .IP "\fBinside\fR" Returns all currently open elements as a list. .IP "\fBassociated\fR" Returns the data associated with the current top most stack content particle or the empty string it there isn't. .RE .TP \&\fB\fBvalidate\fP \fI<XML string>\fB \fI?objVar?\fB \&\fRReturns true if the \fI<XML string>\fR is valid or false otherwise. If validation failed and the optional \&\fIobjVar\fR argument is given, then the variable with that name is set to a validation error message. If the XML string is valid and the optional \fIobjVar\fR argument is given, then the variable with that name is set to the empty string. .TP \&\fB\fBvalidatefile\fP \fIfilename\fB \fI?objVar?\fB \&\fRReturns true if the content of \fIfilename\fR is valid or false otherwise. The given file is feeded as binary stream to expat, therefor only US-ASCII, ISO-8859-1, UTF-8 or UTF-16 encoded data will work with this method. If validation failed and the optional \fIobjVar\fR argument is given, then the variable with that name is set to a validation error message. If the XML string is valid and the optional \fIobjVar\fR argument is given, then the variable with that name is set to the empty string. .TP \&\fB\fBvalidatechannel\fP \fIchannel\fB \fI?objVar?\fB \&\fRReturns true if the content read ouf of the tcl channel \&\fIchannel\fR is valid or false otherwise. Since data read out of a tcl channel is UTF-8 encoded any misleading encoding declaration at the beginning of the data will lead to errors. If the validation failed and the optional \fIobjVar\fR argument is given, then the variable with that name is set to a validation error message. If the XML string is valid and the optional \fIobjVar\fR argument is given, then the variable with that name is set to the empty string. .TP \&\fB\fBdomvalidate\fP \fIdomNode\fB \fI?objVar?\fB \&\fRReturns true if the first argument is a valid tree or false otherwise. If validation failed and the optional \&\fIobjVar\fR argument is given, then the variable with that name is set to a validation error message. If the dom tree is valid and the optional \fIobjVar\fR argument is given, then |
︙ | ︙ | |||
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | \&\fB\fBtcl\fP \fItclcmd\fB \fI?arg arg ...?\fB \&\fREvaluates the Tcl script \fItclcmd arg arg ... \fR and the schema command appended to the argument list. This validation command is only allowed in strict sequential context (not in choice, mixed and interleave). If the return code is something else than 0 (TCL_OK) then this ia a validation error. .TP \&\fB\fBprefixns\fP \fI?prefixUriList?\fB \&\fRThis defines a prefix to namespace URI mapping exactly as a \fIschemacmd prefixns\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\fBdefelement\fP \fIname\fB \fI?namespace?\fB \fI<definition script>\fB | > > > > > > > > > | > > > > > > > | 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | \&\fB\fBtcl\fP \fItclcmd\fB \fI?arg arg ...?\fB \&\fREvaluates the Tcl script \fItclcmd arg arg ... \fR and the schema command appended to the argument list. This validation command is only allowed in strict sequential context (not in choice, mixed and interleave). If the return code is something else than 0 (TCL_OK) then this ia a validation error. .TP \&\fB\fBassociate\fP \fIdata\fB \&\fRThis command is only allowed top-level inside the definition scripts of the element, elementtype, pattern or interleave content particle. Associate the as argument given \&\fIdata\fR with the currently defined content particle and may be requested in scripts evaluated while validating the content of that particle with the schema command method call \&\fIinfo stack associated\fR. .TP \&\fB\fBprefixns\fP \fI?prefixUriList?\fB \&\fRThis defines a prefix to namespace URI mapping exactly as a \fIschemacmd prefixns\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\fBdefelement\fP \fIname\fB \fI?namespace?\fB \fI<definition script>\fB \&\fRThis defines an element 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\fBdefelementtype\fP \fIname\fB \fI?namespace?\fB \fI<definition script>\fB \&\fRThis defines an elementtype exactly as a \fIschemacmd defelementtype\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. |
︙ | ︙ | |||
1084 1085 1086 1087 1088 1089 1090 | foreach e {name email} { defelement $e {text} } } .CE | | > | 1127 1128 1129 1130 1131 1132 1133 1134 1135 | foreach e {name email} { defelement $e {text} } } .CE .SH KEYWORDS Validation, Postvalidation, DOM, SAX |
Changes to doc/schema.xml.
︙ | ︙ | |||
151 152 153 154 155 156 157 158 159 160 161 | <optdef> <optname>text</optname> <optarg>text</optarg> <desc>Checks if the current validation state allows the given text content. It raises error, if not.</desc> </optdef> </optlist> </desc> </commanddef> | > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | <optdef> <optname>text</optname> <optarg>text</optarg> <desc>Checks if the current validation state allows the given text content. It raises error, if not.</desc> </optdef> </optlist> </desc> </commanddef> <commanddef> <command><method>stack</method> <m>(top|inside|associated)</m></command> <desc>In Tcl scripts evaluated by validation this method provides information about the current validation stack. Called outside this context the method returns the empty string. <optlist> <optdef> <optname>top</optname> <desc>Returns the element which content is currently checked (the at the moment open element tag). </desc> </optdef> <optdef> <optname>inside</optname> <desc>Returns all currently open elements as a list.</desc> </optdef> <optdef> <optname>associated</optname> <desc>Returns the data associated with the current top most stack content particle or the empty string it there isn't. </desc> </optdef> </optlist> </desc> </commanddef> <commanddef> <command><method>validate</method> <m><XML string></m> <m>?objVar?</m></command> <desc>Returns true if the <m><XML string></m> is valid or false otherwise. If validation failed and the optional <m>objVar</m> argument is given, then the variable with that name is set to a validation error message. If the XML string is valid and the optional <m>objVar</m> argument is given, |
︙ | ︙ | |||
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | <desc>Evaluates the Tcl script <m>tclcmd arg arg ... </m> and the schema command appended to the argument list. This validation command is only allowed in strict sequential context (not in choice, mixed and interleave). If the return code is something else than 0 (TCL_OK) then this ia a validation error.</desc> </commanddef> <commanddef> <command><method>prefixns</method> <m>?prefixUriList?</m></command> <desc>This defines a prefix to namespace URI mapping exactly as a <i>schemacmd prefixns</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>defelement</method> <m>name</m> <m>?namespace?</m> <m><definition script></m></command> | > > > > > > > > > > > | > > > > > > > > > | 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | <desc>Evaluates the Tcl script <m>tclcmd arg arg ... </m> and the schema command appended to the argument list. This validation command is only allowed in strict sequential context (not in choice, mixed and interleave). If the return code is something else than 0 (TCL_OK) then this ia a validation error.</desc> </commanddef> <commanddef> <command><method>associate</method> <m>data</m></command> <desc>This command is only allowed top-level inside the definition scripts of the element, elementtype, pattern or interleave content particle. Associate the as argument given <m>data</m> with the currently defined content particle and may be requested in scripts evaluated while validating the content of that particle with the schema command method call <m>info stack associated</m>.</desc> </commanddef> <commanddef> <command><method>prefixns</method> <m>?prefixUriList?</m></command> <desc>This defines a prefix to namespace URI mapping exactly as a <i>schemacmd prefixns</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>defelement</method> <m>name</m> <m>?namespace?</m> <m><definition script></m></command> <desc>This defines an element 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>defelementtype</method> <m>name</m> <m>?namespace?</m> <m><definition script></m></command> <desc>This defines an elementtype exactly as a <i>schemacmd defelementtype</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><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> |
︙ | ︙ |
Changes to generic/schema.c.
︙ | ︙ | |||
536 537 538 539 540 541 542 543 544 545 546 547 548 549 | FREE (pattern->childs); } break; } if (pattern->defScript) { Tcl_DecrRefCount (pattern->defScript); } FREE (pattern); } static SchemaData* initSchemaData ( Tcl_Obj *cmdNameObj) { | > > > | 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | FREE (pattern->childs); } break; } if (pattern->defScript) { Tcl_DecrRefCount (pattern->defScript); } if (pattern->associated) { Tcl_DecrRefCount (pattern->associated); } FREE (pattern); } static SchemaData* initSchemaData ( Tcl_Obj *cmdNameObj) { |
︙ | ︙ | |||
3651 3652 3653 3654 3655 3656 3657 | m_validationstate, m_vstate, m_definedElements, m_stack, m_toplevel, m_expected, m_definition, m_validationaction, m_vaction, m_line, m_column, m_domNode, m_nrForwardDefinitions, m_typedefinition, m_definedElementtypes }; static const char *schemaInstanceInfoStackMethods[] = { | | | | 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 | m_validationstate, m_vstate, m_definedElements, m_stack, m_toplevel, m_expected, m_definition, m_validationaction, m_vaction, m_line, m_column, m_domNode, m_nrForwardDefinitions, m_typedefinition, m_definedElementtypes }; static const char *schemaInstanceInfoStackMethods[] = { "top", "inside", "associated", NULL }; enum schemaInstanceInfoStackMethod { m_top, m_inside, m_associated }; static const char *schemaInstanceInfoVactionMethods[] = { "name", "namespace", "text", NULL }; enum schemaInstanceInfoVactionMethod { m_name, m_namespace, m_text |
︙ | ︙ | |||
3722 3723 3724 3725 3726 3727 3728 | } if (Tcl_GetIndexFromObj (interp, objv[2], schemaInstanceInfoStackMethods, "method", 0, &methodIndex) != TCL_OK) { return TCL_ERROR; } | < < | < | | | > > < < < < < > > > > > > > | 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 | } if (Tcl_GetIndexFromObj (interp, objv[2], schemaInstanceInfoStackMethods, "method", 0, &methodIndex) != TCL_OK) { return TCL_ERROR; } if (!sdata->stack) { return TCL_OK; } se = sdata->stack; switch ((enum schemaInstanceInfoStackMethod) methodIndex) { case m_inside: rObj = Tcl_NewObj(); while (se) { if (se->pattern->type == SCHEMA_CTYPE_NAME) { Tcl_ListObjAppendElement (interp, rObj, serializeElementName (interp, se->pattern)); } se = se->down; } Tcl_SetObjResult (interp, rObj); return TCL_OK; case m_top: while (se->pattern->type != SCHEMA_CTYPE_NAME) { se = se->down; } rObj = serializeElementName (interp, se->pattern); Tcl_SetObjResult (interp, rObj); return TCL_OK; case m_associated: if (!se->pattern->associated) { return TCL_OK; } Tcl_SetObjResult (interp, se->pattern->associated); return TCL_OK; } case m_toplevel: if (objc != 2) { Tcl_WrongNumArgs (interp, 2, objv, ""); return TCL_ERROR; } |
︙ | ︙ | |||
5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 | Tcl_GetString (ksObj), NULL); REMEMBER_PATTERN (pattern); pattern->keySpace = Tcl_GetHashValue (h); addToContent (sdata, pattern, SCHEMA_CQUANT_ONE, 0, 0); } return TCL_OK; } static int integerImplXsd ( Tcl_Interp *interp, void *constraintData, char *text ) | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 | Tcl_GetString (ksObj), NULL); REMEMBER_PATTERN (pattern); pattern->keySpace = Tcl_GetHashValue (h); addToContent (sdata, pattern, SCHEMA_CQUANT_ONE, 0, 0); } return TCL_OK; } static int associatePatternObjCmd ( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] ) { SchemaData *sdata = GETASI; CHECK_SI CHECK_TOPLEVEL checkNrArgs (2, 2, "Expected: data"); switch (sdata->cp->type) { case SCHEMA_CTYPE_NAME: case SCHEMA_CTYPE_PATTERN: case SCHEMA_CTYPE_INTERLEAVE: break; default: SetResult ("The associate schema definition command is only " "allowed inside of global or local element, pattern or " "interleval context"); return TCL_ERROR; } if (sdata->cp->associated) { Tcl_DecrRefCount (sdata->cp->associated); } sdata->cp->associated = objv[1]; Tcl_IncrRefCount (sdata->cp->associated); return TCL_OK; } static int integerImplXsd ( Tcl_Interp *interp, void *constraintData, char *text ) |
︙ | ︙ | |||
7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 | Tcl_CreateObjCommand (interp,"tdom::schema::domunique", domuniquePatternObjCmd, NULL, NULL); /* Local key constraints */ Tcl_CreateObjCommand (interp, "tdom::schema::keyspace", keyspacePatternObjCmd, NULL, NULL); /* The text constraint commands */ Tcl_CreateObjCommand (interp,"tdom::schema::text::integer", integerTCObjCmd, (ClientData) 0, NULL); Tcl_CreateObjCommand (interp,"tdom::schema::text::negativeInteger", integerTCObjCmd, (ClientData) 1, NULL); Tcl_CreateObjCommand (interp,"tdom::schema::text::nonNegativeInteger", integerTCObjCmd, (ClientData) 2, NULL); | > > > > | 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 | Tcl_CreateObjCommand (interp,"tdom::schema::domunique", domuniquePatternObjCmd, NULL, NULL); /* Local key constraints */ Tcl_CreateObjCommand (interp, "tdom::schema::keyspace", keyspacePatternObjCmd, NULL, NULL); /* The associate command */ Tcl_CreateObjCommand (interp,"tdom::schema::associate", associatePatternObjCmd, NULL, NULL); /* The text constraint commands */ Tcl_CreateObjCommand (interp,"tdom::schema::text::integer", integerTCObjCmd, (ClientData) 0, NULL); Tcl_CreateObjCommand (interp,"tdom::schema::text::negativeInteger", integerTCObjCmd, (ClientData) 1, NULL); Tcl_CreateObjCommand (interp,"tdom::schema::text::nonNegativeInteger", integerTCObjCmd, (ClientData) 2, NULL); |
︙ | ︙ |
Changes to generic/schema.h.
︙ | ︙ | |||
109 110 111 112 113 114 115 116 117 118 119 120 121 122 | Tcl_HashTable *childs; SchemaAttr **attrs; unsigned int numAttr; unsigned int numReqAttr; domKeyConstraint *domKeys; SchemaKeySpace *keySpace; Tcl_Obj *defScript; } SchemaCP; typedef struct SchemaValidationStack { SchemaCP *pattern; struct SchemaValidationStack *next; struct SchemaValidationStack *down; | > | 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | Tcl_HashTable *childs; SchemaAttr **attrs; unsigned int numAttr; unsigned int numReqAttr; domKeyConstraint *domKeys; SchemaKeySpace *keySpace; Tcl_Obj *defScript; Tcl_Obj *associated; } SchemaCP; typedef struct SchemaValidationStack { SchemaCP *pattern; struct SchemaValidationStack *next; struct SchemaValidationStack *down; |
︙ | ︙ |
Changes to tests/schema.test.
︙ | ︙ | |||
6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 | s delete set result } {defelementtype a b http://my.foo { elementtype a elementtype a2 }} proc schema-18 {args} { lappend ::result {*}$args } test schema-18.1 {reportcmd} { tdom::schema s s define { defelement doc { | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 | s delete set result } {defelementtype a b http://my.foo { elementtype a elementtype a2 }} proc schema-17.19 {schemacmd} { lappend ::result [$schemacmd info stack associated] } test schema-17.19 {info stack associated} { tdom::schema s s defelement doc { element a + } s defelement a { associate "fo bar baz" tcl schema-17.19 } set result [list] foreach xml { <doc><a/></doc> <doc><a/><a/></doc> } { lappend result [s validate $xml] } s delete set result } {{fo bar baz} 1 {fo bar baz} {fo bar baz} 1} proc schema-17.20 {schemacmd args} { lappend ::result [$schemacmd info stack associated] } test schema-17.20 {info stack associated} { tdom::schema s s defelement doc { element a + } s defelement a { associate "fo bar baz" # Only local defined element b ? } s reportcmd schema-17.20 set result [list] foreach xml { <doc></doc> <doc><a/></doc> <doc><a><b/></a></doc> <doc><a><c/></a></doc> <doc><a/><b/></doc> } { lappend result [s validate $xml] } s delete set result } {{} 1 1 1 {fo bar baz} 1 {} 1} proc schema-18 {args} { lappend ::result {*}$args } test schema-18.1 {reportcmd} { tdom::schema s s define { defelement doc { |
︙ | ︙ |