tDOM

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

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

Overview
Comment:Merged from schema.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | localkey
Files: files | file ages | folders
SHA3-256: db1bcdb342d097577603ab3f9d6d244bd09e8020609c63dee61866ce93d1d1cd
User & Date: rolf 2019-05-10 13:05:49
Context
2019-05-10
13:41
Merge from schema. check-in: 4bf39f2571 user: rolf tags: localkey
13:05
Merged from schema. check-in: db1bcdb342 user: rolf tags: localkey
13:04
Futher work on prefixns: allow it als top level command in define script. Changed semantic to first prefix/namespace mapping in prefixUriList wins, if there are several prefixes mapping to different namespaces. check-in: a70c1d6c6e user: rolf tags: schema
00:49
Use the new schema feature prefixns for namespace prefix resolution in local key constraint XPath expressions. check-in: e407c9fd00 user: rolf tags: localkey
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to doc/schema.html.

     1      1   <html>
     2      2   <head>
     3      3   <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">
     4      4   </head><body>
     5      5   <div class="header">
     6      6   <div class="navbar" align="center">
     7         -<a href="#SECTid0x55dce5c8db10">NAME</a> · <a href="#SECTid0x55dce5c8e170">SYNOPSIS</a> · <a href="#SECTid0x55dce5c885f0">DESCRIPTION </a> · <a href="#SECTid0x55dce5ce7e60">Schema definition scripts</a> · <a href="#SECTid0x55dce5cf0190">Quantity specifier</a> · <a href="#SECTid0x55dce5cf2020">Text constraint scripts</a> · <a href="#SECTid0x55dce5cfa430">Exampels</a>
            7  +<a href="#SECTid0x55ce24033b10">NAME</a> · <a href="#SECTid0x55ce24034170">SYNOPSIS</a> · <a href="#SECTid0x55ce2402e5f0">DESCRIPTION </a> · <a href="#SECTid0x55ce2408e1e0">Schema definition scripts</a> · <a href="#SECTid0x55ce24096d00">Quantity specifier</a> · <a href="#SECTid0x55ce24098b90">Text constraint scripts</a> · <a href="#SECTid0x55ce240a0fa0">Exampels</a>
     8      8   </div><hr class="navsep">
     9      9   </div><div class="body">
    10         -  <h2><a name="SECTid0x55dce5c8db10">NAME</a></h2><p class="namesection">
           10  +  <h2><a name="SECTid0x55ce24033b10">NAME</a></h2><p class="namesection">
    11     11   <b class="names">tdom::schema - </b><br>Create a schema validation command</p>
    12     12   
    13         -  <h2><a name="SECTid0x55dce5c8e170">SYNOPSIS</a></h2><pre class="syntax">package require tdom
           13  +  <h2><a name="SECTid0x55ce24034170">SYNOPSIS</a></h2><pre class="syntax">package require tdom
    14     14   
    15     15   <b class="cmd">tdom::schema</b> <i class="m">?create?</i> <i class="m">cmdName</i>
    16     16       </pre>
    17     17   
    18         -  <h2><a name="SECTid0x55dce5c885f0">DESCRIPTION </a></h2><p>This command creates validation commands with a simple API. The
           18  +  <h2><a name="SECTid0x55ce2402e5f0">DESCRIPTION </a></h2><p>This command creates validation commands with a simple API. The
    19     19       validation commands have methods to define a schema and are able
    20     20       to validate XML or DOM trees (and to some degree other kind of
    21     21       hierarchical data) against this schema.</p><p>Additionally, a validation command may be used as argument to
    22     22       the <i class="m">-validateCmd</i> option of the <i class="m">dom parse</i> and the
    23     23       <i class="m">expat</i> commands to enable validation additional to what they
    24     24       otherwise do.</p><p>The valid methods of the created commands are:</p><dl class="commandlist">
    25     25         
    26     26             <dt>
    27     27   <b class="method">prefixns</b> <i class="m">?prefixUriList?</i>
    28     28   </dt>
    29         -
    30     29             <dd>This method gives control to a prefix (or
    31     30             abbreviation) to namespace URI mapping. Everywhere a
    32     31             namespace argument is expected in the schema command methods
    33     32             you may use the "prefix" pointing to the namespace
    34     33             URI in the current prefixUriList, set by this method. If the
    35     34             list map the same prefix to different namespace URIs the
    36         -          last won win. If there isn't such a prefix the namespace
           35  +          frist one win. If there isn't such a prefix the namespace
    37     36             argument is used literally as namespace URI. If the method
    38     37             is called without argument it returns the current
    39         -          prefixUriList. If the method is called with the empty list
           38  +          prefixUriList. If the method is called with the empty string
    40     39             any namespace URI arguments are used literally. This is the
    41     40             default.
    42     41             </dd>
    43     42         
    44     43   
    45     44         
    46     45           <dt>
................................................................................
   185    184           <dt><b class="method">reset</b></dt>
   186    185           <dd>This method resets the validation command into state
   187    186           READY (while preserving the defined grammer).</dd>
   188    187         
   189    188   
   190    189       </dl>
   191    190   
   192         -  <h2><a name="SECTid0x55dce5ce7e60">Schema definition scripts</a></h2><p>Schema definition scripts are ordinary Tcl scripts that are
          191  +  <h2><a name="SECTid0x55ce2408e1e0">Schema definition scripts</a></h2><p>Schema definition scripts are ordinary Tcl scripts that are
   193    192       evaluatend in the namespace tdom::schema. The below listed schema
   194    193       definition commands in this tcl namespace allow to define a wide
   195    194       variety of document structures. Every schema definition command
   196    195       establish a validation constraint on the content which has to
   197    196       match or must be optional to render the content as valid. It is a
   198    197       validation error if the element in the XML source has additional
   199    198       (not matched) content.</p><p>The schema definition commands are:</p><dl class="commandlist">
................................................................................
   301    300         
   302    301           <dt>
   303    302   <b class="method">namespace</b> <i class="m">uri</i> <i class="m">&lt;definition script&gt;</i>
   304    303   </dt>
   305    304           <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>
   306    305         
   307    306         
          307  +      
          308  +        <dt>
          309  +<b class="method">prefixns</b> <i class="m">?prefixUriList?</i>
          310  +</dt>
          311  +        <dd>This defines a prefix to namespace URI mapping exactly
          312  +        as a <i>schemacmd prefixns</i> call. This is meant as toplevel
          313  +        command of a <i>schemacmd define</i> script. This command is
          314  +        not allowed nested in an other definition script command and
          315  +        will raise error, if you call it there.</dd>
          316  +      
          317  +
   308    318         
   309    319           <dt>
   310    320   <b class="method">defelement</b> <i class="m">name</i> <i class="m">?namespace?</i> <i class="m">&lt;definition script&gt;</i>
   311    321   </dt>
   312    322           <dd>This defines an element type exactly as a <i>schemacmd
   313    323           defelement</i> call. This is meant as toplevel command of a
   314    324           <i>schemacmd define</i> script. This command is not allowed
................................................................................
   335    345           call. This is meant as toplevel command of a <i>schemacmd
   336    346           define</i> script. This command is not allowed nested in an
   337    347           other definition script command and will raise error, if you
   338    348           call it there.</dd>
   339    349         
   340    350       </dl>
   341    351   
   342         -  <h2><a name="SECTid0x55dce5cf0190">Quantity specifier</a></h2><p>Serveral schema definition commands expects a quantifier as
          352  +  <h2><a name="SECTid0x55ce24096d00">Quantity specifier</a></h2><p>Serveral schema definition commands expects a quantifier as
   343    353       one of their arguments, which specifies how often the content
   344    354       particle specified by the command is expected. The valid values
   345    355       for a <i class="m">quant</i> argument are:</p><dl class="optlist">
   346    356         
   347    357           <dt><b>!</b></dt>
   348    358           <dd>The content particle must occur exactly once in valid
   349    359           documents. This is the default, if a quantifier is
................................................................................
   380    390           n to m times (both inclusive) in a row in valid documents. The
   381    391           quantifier must be a tcl list with two elements. Both elements
   382    392           must be integers, with n &gt;= 0 and n &lt; m.</dd>
   383    393         
   384    394       </dl><p>If an optional quantifier is not given then it defaults to * in
   385    395       case of the mixed command and to ! for all other commands.</p>
   386    396   
   387         -  <h2><a name="SECTid0x55dce5cf2020">Text constraint scripts</a></h2><p></p><p>The text constraint commands are:</p><dl class="commandlist">
          397  +  <h2><a name="SECTid0x55ce24098b90">Text constraint scripts</a></h2><p></p><p>The text constraint commands are:</p><dl class="commandlist">
   388    398         
   389    399           <dt><b class="cmd">isint</b></dt>
   390    400           <dd></dd>
   391    401         
   392    402   
   393    403         
   394    404           <dt>
................................................................................
   544    554         
   545    555           <dt><b class="cmd">base64</b></dt>
   546    556           <dd>This text constraint match if text is valid according to
   547    557           RFC 4648.</dd>
   548    558         
   549    559       </dl>
   550    560     
   551         -  <h2><a name="SECTid0x55dce5cfa430">Exampels</a></h2><p>The XML Schema Part 0: Primer Second Edition
          561  +  <h2><a name="SECTid0x55ce240a0fa0">Exampels</a></h2><p>The XML Schema Part 0: Primer Second Edition
   552    562       (<a href="https://www.w3.org/TR/xmlschema-0/">https://www.w3.org/TR/xmlschema-0/</a>) starts with this
   553    563       example schema:</p><pre class="example">
   554    564   &lt;xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
   555    565   
   556    566     &lt;xsd:annotation&gt;
   557    567       &lt;xsd:documentation xml:lang="en"&gt;
   558    568        Purchase order schema for Example.com.

Changes to doc/schema.n.

   186    186   \&\fB\fBprefixns\fP \fI?prefixUriList?\fB
   187    187   \&\fRThis method gives control to a prefix (or
   188    188   abbreviation) to namespace URI mapping. Everywhere a
   189    189   namespace argument is expected in the schema command methods
   190    190   you may use the "prefix" pointing to the namespace
   191    191   URI in the current prefixUriList, set by this method. If the
   192    192   list map the same prefix to different namespace URIs the
   193         -last won win. If there isn't such a prefix the namespace
          193  +frist one win. If there isn't such a prefix the namespace
   194    194   argument is used literally as namespace URI. If the method
   195    195   is called without argument it returns the current
   196         -prefixUriList. If the method is called with the empty list
          196  +prefixUriList. If the method is called with the empty string
   197    197   any namespace URI arguments are used literally. This is the
   198    198   default.
   199    199   .TP
   200    200   \&\fB\fBdefelement\fP \fIname\fB \fI?namespace?\fB \fI<definition script>\fB
   201    201   \&\fRThis method defines the element \fIname\fR (optional in
   202    202   the namespace \fInamespace\fR) in the schema. The
   203    203   \&\fIdefinition script\fR is evaluated and defines the content
................................................................................
   367    367   text type name.
   368    368   .TP
   369    369   \&\fB\fBnsattribute\fP \fIname\fB \fInamespace\fB \fI?quant?\fB \fI(?<constraint script>|\*(lqtype\*(lq typename?)\fB
   370    370   \&\fRThis command does the same as the command \fIattribute\fR, just for the attribute \fIname\fR in the namespace \fInamespace\fR.
   371    371   .TP
   372    372   \&\fB\fBnamespace\fP \fIuri\fB \fI<definition script>\fB
   373    373   \&\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.
          374  +.TP
          375  +\&\fB\fBprefixns\fP \fI?prefixUriList?\fB
          376  +\&\fRThis defines a prefix to namespace URI mapping exactly
          377  +as a \fIschemacmd prefixns\fR call. This is meant as toplevel
          378  +command of a \fIschemacmd define\fR script. This command is
          379  +not allowed nested in an other definition script command and
          380  +will raise error, if you call it there.
   374    381   .TP
   375    382   \&\fB\fBdefelement\fP \fIname\fB \fI?namespace?\fB \fI<definition script>\fB
   376    383   \&\fRThis defines an element type exactly as a \fIschemacmd
   377    384   defelement\fR call. This is meant as toplevel command of a
   378    385   \&\fIschemacmd define\fR script. This command is not allowed
   379    386   nested in an other definition script command and will raise
   380    387   error, if you call it there.

Changes to doc/schema.xml.

    26     26       otherwise do.</p>
    27     27   
    28     28       <p>The valid methods of the created commands are:</p>
    29     29   
    30     30       <commandlist>
    31     31         <commanddef>
    32     32             <command><method>prefixns</method> <m>?prefixUriList?</m></command>
    33         -
    34     33             <desc>This method gives control to a prefix (or
    35     34             abbreviation) to namespace URI mapping. Everywhere a
    36     35             namespace argument is expected in the schema command methods
    37     36             you may use the &quot;prefix&quot; pointing to the namespace
    38     37             URI in the current prefixUriList, set by this method. If the
    39     38             list map the same prefix to different namespace URIs the
    40         -          last won win. If there isn't such a prefix the namespace
           39  +          frist one win. If there isn't such a prefix the namespace
    41     40             argument is used literally as namespace URI. If the method
    42     41             is called without argument it returns the current
    43         -          prefixUriList. If the method is called with the empty list
           42  +          prefixUriList. If the method is called with the empty string
    44     43             any namespace URI arguments are used literally. This is the
    45     44             default.
    46     45             </desc>
    47     46         </commanddef>
    48     47   
    49     48         <commanddef>
    50     49           <command><method>defelement</method> <m>name</m> <m>?namespace?</m> <m>&lt;definition script></m></command>
................................................................................
   273    272         </commanddef>
   274    273   
   275    274         <commanddef>
   276    275           <command><method>namespace</method> <m>uri</m> <m>&lt;definition script></m></command>
   277    276           <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>
   278    277         </commanddef>
   279    278         
          279  +      <commanddef>
          280  +        <command><method>prefixns</method> <m>?prefixUriList?</m></command>
          281  +        <desc>This defines a prefix to namespace URI mapping exactly
          282  +        as a <i>schemacmd prefixns</i> call. This is meant as toplevel
          283  +        command of a <i>schemacmd define</i> script. This command is
          284  +        not allowed nested in an other definition script command and
          285  +        will raise error, if you call it there.</desc>
          286  +      </commanddef>
          287  +
   280    288         <commanddef>
   281    289           <command><method>defelement</method> <m>name</m> <m>?namespace?</m> <m>&lt;definition script></m></command>
   282    290           <desc>This defines an element type exactly as a <i>schemacmd
   283    291           defelement</i> call. This is meant as toplevel command of a
   284    292           <i>schemacmd define</i> script. This command is not allowed
   285    293           nested in an other definition script command and will raise
   286    294           error, if you call it there.</desc>

Changes to generic/schema.c.

  2252   2252       ClientData clientData,
  2253   2253       Tcl_Interp *interp,
  2254   2254       int objc,
  2255   2255       Tcl_Obj *const objv[]
  2256   2256       )
  2257   2257   {
  2258   2258       int            methodIndex, keywordIndex, hnew, patternIndex;
  2259         -    int            result = TCL_OK, forwardDef = 0, i = 0;
         2259  +    int            result = TCL_OK, forwardDef = 0, i = 0, j;
  2260   2260       int            savedDefineToplevel, type, len;
  2261   2261       unsigned int   savedNumPatternList;
  2262   2262       SchemaData    *savedsdata = NULL, *sdata = (SchemaData *) clientData;
  2263   2263       Tcl_HashTable *hashTable;
  2264   2264       Tcl_HashEntry *h, *h1;
  2265   2265       SchemaCP      *pattern, *current = NULL;
  2266   2266       void          *namespacePtr, *savedNamespacePtr;
................................................................................
  2286   2286       };
  2287   2287   
  2288   2288       enum eventKeyword
  2289   2289       {
  2290   2290           k_elementstart, k_elementend, k_text
  2291   2291       };
  2292   2292   
  2293         -    if (objc < 2) {
  2294         -        Tcl_WrongNumArgs (interp, 1, objv, "subcommand ?arguments?");
  2295         -        return TCL_ERROR;
  2296         -    }
  2297         -
  2298   2293       if (sdata == NULL) {
  2299         -        /* Inline defined defelement, defpattern, deftext or start */
         2294  +        /* Inline defined defelement, defpattern, deftext, start or
         2295  +         * prefixns */
  2300   2296           sdata = GETASI;
  2301   2297           CHECK_SI;
  2302   2298           if (!sdata->defineToplevel && sdata->currentEvals > 1) {
  2303   2299               SetResult ("Method not allowed in nested schema define script");
  2304   2300               return TCL_ERROR;
  2305   2301           }
  2306   2302           i = 1;
  2307   2303       }
         2304  +    if (objc + i < 2) {
         2305  +        Tcl_WrongNumArgs (interp, 1, objv, "subcommand ?arguments?");
         2306  +        return TCL_ERROR;
         2307  +    }
         2308  +
  2308   2309   
  2309   2310       if (Tcl_GetIndexFromObj (interp, objv[1-i], schemaInstanceMethods,
  2310   2311                                "method", 0, &methodIndex)
  2311   2312           != TCL_OK) {
  2312   2313           return TCL_ERROR;
  2313   2314       }
  2314   2315   
................................................................................
  2647   2648               Tcl_DecrRefCount (sdata->reportCmd);
  2648   2649           }
  2649   2650           sdata->reportCmd = objv[2];
  2650   2651           Tcl_IncrRefCount (sdata->reportCmd);
  2651   2652           break;
  2652   2653   
  2653   2654       case m_prefixns:
         2655  +        CHECK_RECURSIVE_CALL
         2656  +        if (clientData == NULL && !sdata->defineToplevel) {
         2657  +            SetResult ("Command only allowed at lop level");
         2658  +            return TCL_ERROR;
         2659  +        }
         2660  +        if (objc != 2-i && objc != 3-i) {
         2661  +            Tcl_WrongNumArgs (interp, 2-i, objv, "?prefixUriList?");
         2662  +            return TCL_ERROR;
         2663  +        }
         2664  +        if (!i) {objc--; objv++;}
  2654   2665           result = tcldom_prefixNSlist (&sdata->prefixns, interp, objc, objv,
  2655   2666                                         "prefixns");
  2656   2667           if (sdata->prefix.numBuckets) {
  2657   2668               Tcl_DeleteHashTable (&sdata->prefix);
  2658   2669               Tcl_InitHashTable (&sdata->prefix, TCL_STRING_KEYS);
  2659   2670           }
  2660   2671           if (result == TCL_OK && sdata->prefixns) {
  2661         -            i = 0;
  2662         -            while (sdata->prefixns[i]) {
  2663         -                h = Tcl_CreateHashEntry (&sdata->namespace,
  2664         -                                         sdata->prefixns[i+1], &hnew);
         2672  +            j = 0;
         2673  +            while (sdata->prefixns[j]) {
  2665   2674                   h1 = Tcl_CreateHashEntry (&sdata->prefix,
  2666         -                                          sdata->prefixns[i], &hnew);
  2667         -                Tcl_SetHashValue (h1, Tcl_GetHashKey (&sdata->namespace, h));
  2668         -                i += 2;
         2675  +                                          sdata->prefixns[j], &hnew);
         2676  +                /* This means: First prefix mapping wins */
         2677  +                if (hnew) {
         2678  +                    h = Tcl_CreateHashEntry (&sdata->namespace,
         2679  +                                             sdata->prefixns[j+1], &hnew);
         2680  +                    Tcl_SetHashValue (h1, Tcl_GetHashKey (&sdata->namespace,
         2681  +                                                          h));
         2682  +                }
         2683  +                j += 2;
  2669   2684               }
  2670   2685           }
  2671   2686           break;
  2672   2687           
  2673   2688       default:
  2674   2689           Tcl_SetResult (interp, "unknown method", NULL);
  2675   2690           result = TCL_ERROR;
................................................................................
  4606   4621       Tcl_CreateObjCommand (interp, "tdom::schema::defelement",
  4607   4622                             schemaInstanceCmd, NULL, NULL);
  4608   4623       Tcl_CreateObjCommand (interp, "tdom::schema::defpattern",
  4609   4624                             schemaInstanceCmd, NULL, NULL);
  4610   4625       Tcl_CreateObjCommand (interp, "tdom::schema::deftext",
  4611   4626                             schemaInstanceCmd, NULL, NULL);
  4612   4627       Tcl_CreateObjCommand (interp, "tdom::schema::start",
         4628  +                          schemaInstanceCmd, NULL, NULL);
         4629  +    Tcl_CreateObjCommand (interp, "tdom::schema::prefixns",
  4613   4630                             schemaInstanceCmd, NULL, NULL);
  4614   4631   
  4615   4632       /* The "any" definition command. */
  4616   4633       Tcl_CreateObjCommand (interp, "tdom::schema::any",
  4617   4634                             AnyPatternObjCmd, NULL, NULL);
  4618   4635   
  4619   4636       /* The named pattern commands "element" and "ref". */

Changes to generic/tcldom.c.

  3956   3956       const char  *methodName
  3957   3957       )
  3958   3958   {
  3959   3959       char   **prefixns = *prefixnsPtr;
  3960   3960       int      len, i, result;
  3961   3961       Tcl_Obj *objPtr, *listPtr;
  3962   3962   
  3963         -    CheckArgs (2,3,2, "?prefixUriList?");
  3964   3963       i = 0;
  3965         -    if (objc == 2) {
         3964  +    if (objc == 1) {
  3966   3965           if (!prefixns) return TCL_OK;
  3967   3966           listPtr = Tcl_NewListObj (0, NULL);
  3968   3967           i = 0;
  3969   3968           while (prefixns[i]) {
  3970   3969               Tcl_ListObjAppendElement (
  3971   3970                   interp, listPtr, Tcl_NewStringObj (prefixns[i], -1)
  3972   3971                   );
  3973   3972               i++;
  3974   3973           }
  3975   3974           Tcl_SetObjResult (interp, listPtr);
  3976   3975           return TCL_OK;
  3977   3976       }
  3978         -    result = Tcl_ListObjLength (interp, objv[2], &len);
         3977  +    result = Tcl_ListObjLength (interp, objv[1], &len);
  3979   3978       if (result != TCL_OK || (len % 2) != 0) {
  3980         -        SetResult3 ("The optional argument to the ", methodName, 
  3981         -                   " method must be a 'prefix namespace' pairs list");
         3979  +        SetResult3 ("The optional argument to ", methodName, 
         3980  +                   " must be a 'prefix namespace' pairs list");
  3982   3981           return TCL_ERROR;
  3983   3982       }
  3984   3983       if (prefixns) {
  3985   3984           while (prefixns[i]) {
  3986   3985               FREE (prefixns[i]);
  3987   3986               i++;
  3988   3987           }
................................................................................
  3994   3993       }
  3995   3994       if (i < len + 1) {
  3996   3995           if (prefixns) FREE (prefixns);
  3997   3996           prefixns = MALLOC (sizeof (char*) * (len+1));
  3998   3997           *prefixnsPtr = prefixns;
  3999   3998       }
  4000   3999       for (i = 0; i < len; i++) {
  4001         -        Tcl_ListObjIndex (interp, objv[2], i, &objPtr);
         4000  +        Tcl_ListObjIndex (interp, objv[1], i, &objPtr);
  4002   4001           prefixns[i] = tdomstrdup (Tcl_GetString (objPtr));
  4003   4002       }
  4004   4003       prefixns[len] = NULL;
  4005         -    Tcl_SetObjResult (interp, objv[2]);
         4004  +    Tcl_SetObjResult (interp, objv[1]);
  4006   4005       return TCL_OK;
  4007   4006   }
  4008   4007   
  4009   4008   /*----------------------------------------------------------------------------
  4010   4009   |   renameNodes
  4011   4010   |
  4012   4011   \---------------------------------------------------------------------------*/
................................................................................
  5931   5930               SetResult("DOCUMENT_NODE");
  5932   5931               return TCL_OK;
  5933   5932   
  5934   5933           case m_cdataSectionElements:
  5935   5934               return cdataSectionElements (doc, interp, objc, objv);
  5936   5935   
  5937   5936           case m_selectNodesNamespaces:
  5938         -            return tcldom_prefixNSlist (&(doc->prefixNSMappings), interp, objc,
  5939         -                                        objv, "selectNodesNamespaces");
         5937  +            CheckArgs (2,3,2, "?prefixUriList?");
         5938  +            return tcldom_prefixNSlist (&(doc->prefixNSMappings), interp,
         5939  +                                        --objc, ++objv,
         5940  +                                        "selectNodesNamespaces");
  5940   5941               
  5941   5942           case m_renameNode:
  5942   5943               return renameNodes (doc, interp, objc, objv);
  5943   5944               
  5944   5945           case m_deleteXPathCache:
  5945   5946               return deleteXPathCache (doc, interp, objc, objv);
  5946   5947   

Changes to tests/domDoc.test.

  1391   1391   
  1392   1392   test domDoc-25.4 {selectNodesNamespaces} {
  1393   1393       set doc [dom createDocument foo]
  1394   1394       set result [catch {$doc selectNodesNamespaces wrong} errMsg]
  1395   1395       lappend result $errMsg
  1396   1396       $doc delete
  1397   1397       set result
  1398         -} {1 {The optional argument to the selectNodesNamespaces method must be a 'prefix namespace' pairs list}}
         1398  +} {1 {The optional argument to selectNodesNamespaces must be a 'prefix namespace' pairs list}}
  1399   1399   
  1400   1400   test domDoc-25.5 {selectNodesNamespaces} {
  1401   1401       set doc [dom parse {<root xmlns="rootdefaultNS">
  1402   1402           <elem1 xmlns="elem1NS"><elem11/></elem1>
  1403   1403           <elem2 xmlns="elem2NS"/>
  1404   1404           </root>}]
  1405   1405       $doc selectNodesNamespaces {default1 rootdefaultNS}

Changes to tests/schema.test.

   390    390           lappend result [s2 validate $xml]
   391    391       }
   392    392       s2 delete
   393    393       s1 delete
   394    394       set result
   395    395   } {s1 s2 1 0 0 1}
   396    396   
   397         -test schema-1.22 {Call not toplevel cmd methods in definition script} {
          397  +test schema-1.22 {nrForwardDefinitions} {
   398    398       tdom::schema create s
   399    399       set result [list]
   400    400       s define {
   401    401           defelement e {
   402    402               lappend ::result [s nrForwardDefinitions]
   403    403               element e1
   404    404               lappend ::result [s nrForwardDefinitions]
................................................................................
   412    412               lappend ::result [s nrForwardDefinitions]
   413    413           }
   414    414       }
   415    415       s delete
   416    416       set result
   417    417   } {0 1 1 2 1 0}
   418    418   
          419  +test schema-1.23 {prefixns} {
          420  +    tdom::schema create s
          421  +    set result [list]
          422  +    lappend result [s prefixns]
          423  +    lappend result [s prefixns {a b}]
          424  +    lappend result [s prefixns]
          425  +    lappend result [s prefixns {a b a b c d}]
          426  +    lappend result [s prefixns {}]
          427  +    lappend result [s prefixns ""]
          428  +    lappend result [catch {s prefixns a b c} errMsg]
          429  +    lappend result $errMsg
          430  +    lappend result [catch {s prefixns {a b c}} errMsg]
          431  +    lappend result $errMsg
          432  +    lappend result [catch {s prefixns "a \{"} errMsg]
          433  +    lappend result $errMsg
          434  +    s delete
          435  +    set result
          436  +} {{} {a b} {a b} {a b a b c d} {} {} 1 {wrong # args: should be "s prefixns ?prefixUriList?"} 1 {The optional argument to prefixns must be a 'prefix namespace' pairs list} 1 {The optional argument to prefixns must be a 'prefix namespace' pairs list}}
          437  +
          438  +test schema-1.24 {prefixns} {
          439  +    tdom::schema create s
          440  +    set result [list]
          441  +    lappend result [s define prefixns]
          442  +    lappend result [s define {prefixns {a b}}]
          443  +    lappend result [s define {prefixns}]
          444  +    lappend result [s define {prefixns {a b a b c d}}]
          445  +    lappend result [s define {prefixns {}}]
          446  +    lappend result [s define {prefixns ""}]
          447  +    lappend result [catch {s define {prefixns a b c}} errMsg]
          448  +    lappend result $errMsg
          449  +    lappend result [catch {s define {prefixns {a b c}}} errMsg]
          450  +    lappend result $errMsg
          451  +    lappend result [catch {s define {prefixns "a \{"}} errMsg]
          452  +    lappend result $errMsg
          453  +    s delete
          454  +    set result
          455  +} {{} {a b} {a b} {a b a b c d} {} {} 1 {wrong # args: should be "prefixns ?prefixUriList?"} 1 {The optional argument to prefixns must be a 'prefix namespace' pairs list} 1 {The optional argument to prefixns must be a 'prefix namespace' pairs list}}
          456  +
          457  +test schema-1.25 {prefixns} {
          458  +    set result [list]
          459  +    set schema {
          460  +        defelement doc ns1 {
          461  +            element e
          462  +        }
          463  +    }
          464  +    set xml {<doc xmlns="http://tdom.org/test"><e/></doc>}
          465  +    # 1
          466  +    tdom::schema create s
          467  +    s define $schema
          468  +    lappend result [s validate $xml]
          469  +    s delete
          470  +    # 2
          471  +    tdom::schema create s
          472  +    s prefixns {ns1 http://tdom.org/test}
          473  +    s define $schema
          474  +    lappend result [s validate $xml]
          475  +    s delete
          476  +    # 3
          477  +    tdom::schema create s
          478  +    s prefixns {ns1 http://foo.bar}
          479  +    s define $schema
          480  +    lappend result [s validate $xml]
          481  +    s delete
          482  +    # 4
          483  +    tdom::schema create s
          484  +    s prefixns {ns1 http://tdom.org/test ns1 http://foo.bar}
          485  +    s define $schema
          486  +    lappend result [s validate $xml]
          487  +    s delete
          488  +    # 5
          489  +    tdom::schema create s
          490  +    s prefixns {ns1 http://foo.bar ns1 http://tdom.org/test}
          491  +    s define $schema
          492  +    lappend result [s validate $xml]
          493  +    s delete
          494  +    # 6
          495  +    tdom::schema create s
          496  +    s prefixns {ns1 http://foo.bar}
          497  +    s prefixns {ns1 http://tdom.org/test ns1 http://foo.bar}
          498  +    s define $schema
          499  +    lappend result [s validate $xml]
          500  +    s delete
          501  +    # 7
          502  +    tdom::schema create s
          503  +    s define {
          504  +        prefixns {ns1 http://tdom.org/test}
          505  +        defelement doc ns1 {
          506  +            element e
          507  +        }
          508  +        prefixns {ns2 http://foo.bar}
          509  +        defelement e ns2 {text {minLength 1}}
          510  +    }
          511  +    lappend result [s validate $xml]
          512  +    s delete
          513  +    # 8
          514  +    tdom::schema create s
          515  +    s define {
          516  +        prefixns {ns1 http://tdom.org/test}
          517  +        defelement doc ns1 {
          518  +            namespace http://foo.bar {
          519  +                element e 
          520  +            }
          521  +        }
          522  +        prefixns {ns2 http://foo.bar}
          523  +        defelement e ns2 {text {minLength 1}}
          524  +    }
          525  +    lappend result [s validate $xml]
          526  +    # 9
          527  +    lappend result [s validate {<doc xmlns="http://tdom.org/test"><e xmlns="http://foo.bar"/></doc>}]
          528  +    # 10
          529  +    lappend result [s validate {<doc xmlns="http://tdom.org/test"><e xmlns="http://foo.bar">foo</e></doc>}]
          530  +    s delete
          531  +    # 11 
          532  +    tdom::schema create s
          533  +    s define {
          534  +        prefixns {ns1 http://tdom.org/test ns2 http://foo.bar}
          535  +        defelement doc ns1 {
          536  +            namespace ns2 {
          537  +                element e 
          538  +            }
          539  +        }
          540  +        prefixns {ns2 http://foo.bar}
          541  +        defelement e ns2 {text {minLength 1}}
          542  +    }
          543  +    lappend result [s validate $xml]
          544  +    # 12
          545  +    lappend result [s validate {<doc xmlns="http://tdom.org/test"><e xmlns="http://foo.bar"/></doc>}]
          546  +    # 13
          547  +    lappend result [s validate {<doc xmlns="http://tdom.org/test"><e xmlns="http://foo.bar">foo</e></doc>}]
          548  +    s delete
          549  +    set result
          550  +} {0 1 0 1 0 1 1 0 0 1 0 0 1}
          551  +
          552  +test schema-1.26 {prefixns} {
          553  +    tdom::schema create s
          554  +    set result [list]
          555  +    lappend result [catch {
          556  +        s defelement doc {
          557  +            prefixns {a http://foo.bar}
          558  +            namespace a {
          559  +                element e
          560  +            }
          561  +        }
          562  +    } errMsg]
          563  +    lappend result $errMsg
          564  +    lappend result [catch {
          565  +        s defelement doc {
          566  +            namespace a {
          567  +                element e
          568  +            }
          569  +            prefixns {a http://foo.bar}
          570  +        }
          571  +    } errMsg]
          572  +    lappend result $errMsg
          573  +    lappend result [catch {
          574  +        s define {
          575  +            defelement doc {
          576  +                prefixns {a http://foo.bar}
          577  +                namespace a {
          578  +                    element e
          579  +                }
          580  +            }
          581  +        }
          582  +    } errMsg]
          583  +    lappend result $errMsg
          584  +    lappend result [catch {
          585  +        s define {
          586  +            defelement doc {
          587  +                s prefixns {a http://foo.bar}
          588  +                namespace a {
          589  +                    element e
          590  +                }
          591  +            }
          592  +        }
          593  +    } errMsg]
          594  +    lappend result $errMsg
          595  +    s delete
          596  +    set result
          597  +} {1 {Command only allowed at lop level} 1 {Command only allowed at lop level} 1 {Method not allowed in nested schema define script} 1 {This recursive call is not allowed}}
          598  +
   419    599   test schema-2.1 {grammar definition: ref} {
   420    600       tdom::schema create grammar
   421    601       grammar defpattern thisPattern {
   422    602           element a
   423    603           element b
   424    604       }
   425    605       grammar defpattern thatPattern {
................................................................................
  3287   3467           element e ! {
  3288   3468               nsattribute this http://tdom.org/test {
  3289   3469                   minLength 2
  3290   3470                   maxLength 4
  3291   3471               }
  3292   3472               nsattribute foo http://tdom.org/test ? type len2-4
  3293   3473           }
         3474  +    }
         3475  +    set result [list]
         3476  +    foreach xml {
         3477  +        <doc><e/></doc>
         3478  +        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:foo="bar"/></doc>}
         3479  +        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:this="bar"/></doc>}
         3480  +        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:this=""/></doc>}
         3481  +        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:this="12" ns1:foo="bar"/></doc>}
         3482  +        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:this="12" ns1:foo="b"/></doc>}
         3483  +        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:this="1234"/></doc>}
         3484  +        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:this="12345"/></doc>}
         3485  +        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:this="12345alkajsdlfjkals" ns1:and="this"/></doc>}
         3486  +        {<doc xmlns:ns1="http://tdom.org/test"><e ns1:and="this" ns1:this="12345alkajsdlfjkals"/></doc>}
         3487  +    } {
         3488  +        lappend result [s validate $xml]
         3489  +    }
         3490  +    s delete
         3491  +    set result
         3492  +} {0 0 1 0 1 0 1 0 0 0}
         3493  +
         3494  +test schema-14.20a {deftext} {
         3495  +    tdom::schema s
         3496  +    s deftext len2-4 {
         3497  +        minLength 2
         3498  +        maxLength 4
         3499  +    }
         3500  +    s define {
         3501  +        prefixns {
         3502  +            ns2 http://tdom.org/test
         3503  +            nsfoo http://foo.bar
         3504  +            ns2 http://baz.boo
         3505  +        }
         3506  +        defelement doc {
         3507  +            element e ! {
         3508  +                nsattribute this ns2 {
         3509  +                    minLength 2
         3510  +                    maxLength 4
         3511  +                }
         3512  +                nsattribute foo ns2 ? type len2-4
         3513  +            }
         3514  +        }
  3294   3515       }
  3295   3516       set result [list]
  3296   3517       foreach xml {
  3297   3518           <doc><e/></doc>
  3298   3519           {<doc xmlns:ns1="http://tdom.org/test"><e ns1:foo="bar"/></doc>}
  3299   3520           {<doc xmlns:ns1="http://tdom.org/test"><e ns1:this="bar"/></doc>}
  3300   3521           {<doc xmlns:ns1="http://tdom.org/test"><e ns1:this=""/></doc>}