tDOM

Check-in [ee3147fc64]
Login
Bounty program for improvements to Tcl and certain Tcl packages.

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 | wip
Files: files | file ages | folders
SHA3-256: ee3147fc64a2154e1229a5004ba7a0614484fc6c18568f501be56b59749f03f8
User & Date: rolf 2020-03-14 12:05:23
Context
2020-03-15
01:20
wip check-in: 899c21f84b user: rolf tags: wip
2020-03-14
12:05
Merged from schema. check-in: ee3147fc64 user: rolf tags: wip
03:25
Added flag -ignorematched to the schema commant submethod info expected. check-in: 0dc7c2f6cc user: rolf tags: schema
2020-03-12
11:20
Save work. check-in: 5efdc81019 user: rolf tags: wip
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/schema.c.

3231
3232
3233
3234
3235
3236
3237
3238
3239



3240
3241

3242
3243
3244
3245
3246
3247
3248
....
3546
3547
3548
3549
3550
3551
3552
3553

3554
3555
3556
3557
3558
3559
3560




3561

3562
3563
3564
3565
3566
3567
3568
....
3582
3583
3584
3585
3586
3587
3588
3589

3590
3591
3592
3593
3594
3595
3596
....
3619
3620
3621
3622
3623
3624
3625
3626

3627
3628
3629
3630
3631
3632
3633
....
3727
3728
3729
3730
3731
3732
3733
3734

3735
3736
3737
3738
3739
3740
3741
....
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
3770
3771
3772
3773
....
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
....
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933









3934
3935
3936
3937
3938
3939
3940
....
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
    if (sdata->skipDeep == 0) {
        if (node->firstAttr) {
            if (probeDomAttributes (interp, sdata, node->firstAttr) != TCL_OK) {
                return TCL_ERROR;
            }
        } else {
            if (sdata->stack->pattern->numReqAttr) {
                /* probeDomAttributes fills interp result with a msg which
                 * required attributes are missing. */



                probeDomAttributes (interp, sdata, NULL);
                return TCL_ERROR;

            }
        }
    }

    if (sdata->stack->pattern->domKeys) {
        if (checkdomKeyConstraints (interp, sdata, node) != TCL_OK)
            return TCL_ERROR;
................................................................................

static int
getNextExpectedWorker (
    SchemaData *sdata,
    SchemaValidationStack *se,
    Tcl_Interp *interp,
    Tcl_HashTable *seenCPs,
    Tcl_Obj *rObj

    )
{
    int ac, hm, i, hnew, mustMatch, mayskip, rc = 1;
    SchemaCP *cp, *ic, *jc;
    SchemaValidationStack *se1;

    getContext (cp, ac, hm);




    if (hm && maxOne(cp->quants[ac])) ac++;

    switch (cp->type) {
    case SCHEMA_CTYPE_INTERLEAVE:
        ac = 0;
        mustMatch = 0;
        /* Fall through */
    case SCHEMA_CTYPE_NAME:
    case SCHEMA_CTYPE_PATTERN:
................................................................................
                break;
            case SCHEMA_CTYPE_INTERLEAVE:
            case SCHEMA_CTYPE_PATTERN:
                Tcl_CreateHashEntry (seenCPs, ic, &hnew);
                if (hnew) {
                    se1 = getStackElement (sdata, ic);
                    mayskip = getNextExpectedWorker (sdata, se1, interp,
                                                     seenCPs, rObj);

                    repoolStackElement (sdata, se1);
                }
                break;

            case SCHEMA_CTYPE_ANY:
                Tcl_ListObjAppendElement (interp, rObj,
                                          serializeAnyCP (interp, ic));
................................................................................
                        break;
                    case SCHEMA_CTYPE_INTERLEAVE:
                    case SCHEMA_CTYPE_PATTERN:
                        Tcl_CreateHashEntry (seenCPs, jc, &hnew);
                        if (hnew) {
                            se1 = getStackElement (sdata, ic);
                            mayskip = getNextExpectedWorker (
                                sdata, se1, interp, seenCPs, rObj

                                );
                            repoolStackElement (sdata, se1);
                        }
                        break;
                    case SCHEMA_CTYPE_ANY:
                        Tcl_ListObjAppendElement (
                            interp, rObj, serializeAnyCP (interp, jc)
................................................................................
    Tcl_DeleteHashTable (htable);
    return rObj;
}

static void
getNextExpected (
    SchemaData *sdata,
    Tcl_Interp *interp

    )
{
    int remainingLastMatch, count, rc;
    Tcl_Obj *rObj;
    Tcl_HashTable localHash;
    SchemaValidationStack *se;

................................................................................
    remainingLastMatch = 0;
    if (sdata->lastMatchse) {
        se = sdata->lastMatchse;
        while (se->down) {
            remainingLastMatch++;
            se = se->down;
        }
        while (se && getNextExpectedWorker (sdata, se, interp, &localHash, rObj)) {

            if (remainingLastMatch) {
                count = 1;
                se = sdata->lastMatchse;
                while (count < remainingLastMatch) {
                    se = se->down;
                    count++;
                }
................................................................................
                remainingLastMatch--;
            } else break;
        }
    }
    
    se = sdata->stack;
    while (se) {
        rc = getNextExpectedWorker (sdata, se, interp, &localHash, rObj);

        if (se->pattern->type == SCHEMA_CTYPE_NAME) break;
        se = se->down;
        if (!rc) {
            if (mayMiss(se->pattern->quants[se->activeChild])) continue;
            break;
        }
    }
................................................................................
schemaInstanceInfoCmd (
    SchemaData *sdata,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[]
    )
{
    int methodIndex;
    long line, column;
    Tcl_HashEntry *h;
    SchemaCP *cp;
    SchemaValidationStack *se;
    void *ns;
    Tcl_Obj *rObj;
    
................................................................................
            SetBooleanResult (0);
        } else {
            SetBooleanResult (1);
        }
        return TCL_OK;

    case m_expected:
        if (objc != 2) {
            Tcl_WrongNumArgs (interp, 2, objv, "");
            return TCL_ERROR;
        }









        if (sdata->validationState == VALIDATION_ERROR
            || sdata->validationState == VALIDATION_FINISHED) {
            return TCL_OK;
        }
        if (!sdata->stack) {
            if (sdata->start) {
                Tcl_AppendElement (interp, sdata->start);
................................................................................
                if (sdata->startNamespace) {
                    Tcl_AppendElement (interp, sdata->startNamespace);
                }
            } else {
                definedElements (sdata, interp);
            }
        } else {
            getNextExpected (sdata, interp);
        }
        break;
        
    case m_definition:
        if (objc < 3 && objc > 4) {
            Tcl_WrongNumArgs (interp, 1, objv, "name ?namespace?");
            return TCL_ERROR;






|
|
>
>
>
|
|
>







 







|
>







>
>
>
>
|
>







 







|
>







 







|
>







 







|
>







 







|
>







 







|
>







 







|







 







|
|


>
>
>
>
>
>
>
>
>







 







|







3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
....
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
....
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
....
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
....
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
....
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
....
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
....
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
....
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
....
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
    if (sdata->skipDeep == 0) {
        if (node->firstAttr) {
            if (probeDomAttributes (interp, sdata, node->firstAttr) != TCL_OK) {
                return TCL_ERROR;
            }
        } else {
            if (sdata->stack->pattern->numReqAttr) {
                /* probeDomAttributes fills interp result with a msg
                 * which required attributes are missing in case of no
                 * reportCmd. In case of reportCmd
                 * probeDomAttributes() returns only error in the case
                 * of error in called scripts. */
                if (probeDomAttributes (interp, sdata, NULL) != TCL_OK) {
                    return TCL_ERROR;
                }
            }
        }
    }

    if (sdata->stack->pattern->domKeys) {
        if (checkdomKeyConstraints (interp, sdata, node) != TCL_OK)
            return TCL_ERROR;
................................................................................

static int
getNextExpectedWorker (
    SchemaData *sdata,
    SchemaValidationStack *se,
    Tcl_Interp *interp,
    Tcl_HashTable *seenCPs,
    Tcl_Obj *rObj,
    int ignoreMatched
    )
{
    int ac, hm, i, hnew, mustMatch, mayskip, rc = 1;
    SchemaCP *cp, *ic, *jc;
    SchemaValidationStack *se1;

    getContext (cp, ac, hm);
    if (ignoreMatched && hm) {
        ac++;
        hm = 0;
    } else {
        if (hm && maxOne(cp->quants[ac])) ac++;
    }
    switch (cp->type) {
    case SCHEMA_CTYPE_INTERLEAVE:
        ac = 0;
        mustMatch = 0;
        /* Fall through */
    case SCHEMA_CTYPE_NAME:
    case SCHEMA_CTYPE_PATTERN:
................................................................................
                break;
            case SCHEMA_CTYPE_INTERLEAVE:
            case SCHEMA_CTYPE_PATTERN:
                Tcl_CreateHashEntry (seenCPs, ic, &hnew);
                if (hnew) {
                    se1 = getStackElement (sdata, ic);
                    mayskip = getNextExpectedWorker (sdata, se1, interp,
                                                     seenCPs, rObj,
                                                     ignoreMatched);
                    repoolStackElement (sdata, se1);
                }
                break;

            case SCHEMA_CTYPE_ANY:
                Tcl_ListObjAppendElement (interp, rObj,
                                          serializeAnyCP (interp, ic));
................................................................................
                        break;
                    case SCHEMA_CTYPE_INTERLEAVE:
                    case SCHEMA_CTYPE_PATTERN:
                        Tcl_CreateHashEntry (seenCPs, jc, &hnew);
                        if (hnew) {
                            se1 = getStackElement (sdata, ic);
                            mayskip = getNextExpectedWorker (
                                sdata, se1, interp, seenCPs, rObj,
                                ignoreMatched
                                );
                            repoolStackElement (sdata, se1);
                        }
                        break;
                    case SCHEMA_CTYPE_ANY:
                        Tcl_ListObjAppendElement (
                            interp, rObj, serializeAnyCP (interp, jc)
................................................................................
    Tcl_DeleteHashTable (htable);
    return rObj;
}

static void
getNextExpected (
    SchemaData *sdata,
    Tcl_Interp *interp,
    int         ignoreMatched
    )
{
    int remainingLastMatch, count, rc;
    Tcl_Obj *rObj;
    Tcl_HashTable localHash;
    SchemaValidationStack *se;

................................................................................
    remainingLastMatch = 0;
    if (sdata->lastMatchse) {
        se = sdata->lastMatchse;
        while (se->down) {
            remainingLastMatch++;
            se = se->down;
        }
        while (se && getNextExpectedWorker (sdata, se, interp, &localHash, rObj,
                   ignoreMatched)) {
            if (remainingLastMatch) {
                count = 1;
                se = sdata->lastMatchse;
                while (count < remainingLastMatch) {
                    se = se->down;
                    count++;
                }
................................................................................
                remainingLastMatch--;
            } else break;
        }
    }
    
    se = sdata->stack;
    while (se) {
        rc = getNextExpectedWorker (sdata, se, interp, &localHash, rObj,
                                    ignoreMatched);
        if (se->pattern->type == SCHEMA_CTYPE_NAME) break;
        se = se->down;
        if (!rc) {
            if (mayMiss(se->pattern->quants[se->activeChild])) continue;
            break;
        }
    }
................................................................................
schemaInstanceInfoCmd (
    SchemaData *sdata,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[]
    )
{
    int methodIndex, ignoreMatched;
    long line, column;
    Tcl_HashEntry *h;
    SchemaCP *cp;
    SchemaValidationStack *se;
    void *ns;
    Tcl_Obj *rObj;
    
................................................................................
            SetBooleanResult (0);
        } else {
            SetBooleanResult (1);
        }
        return TCL_OK;

    case m_expected:
        if (objc != 2 && objc != 3) {
            Tcl_WrongNumArgs (interp, 2, objv, "?-ignorematched?");
            return TCL_ERROR;
        }
        ignoreMatched = 0;
        if (objc == 3) {
            if (strcmp (Tcl_GetString (objv[2]), "-ignorematched") != 0) {
                SetResult ("Expected -ignorematched");
                return TCL_ERROR;
            }
            ignoreMatched = 1;
        }
        
        if (sdata->validationState == VALIDATION_ERROR
            || sdata->validationState == VALIDATION_FINISHED) {
            return TCL_OK;
        }
        if (!sdata->stack) {
            if (sdata->start) {
                Tcl_AppendElement (interp, sdata->start);
................................................................................
                if (sdata->startNamespace) {
                    Tcl_AppendElement (interp, sdata->startNamespace);
                }
            } else {
                definedElements (sdata, interp);
            }
        } else {
            getNextExpected (sdata, interp, ignoreMatched);
        }
        break;
        
    case m_definition:
        if (objc < 3 && objc > 4) {
            Tcl_WrongNumArgs (interp, 1, objv, "name ?namespace?");
            return TCL_ERROR;

Changes to tests/schema.test.

3501
3502
3503
3504
3505
3506
3507



















3508
3509
3510
3511
3512
3513
3514
....
6320
6321
6322
6323
6324
6325
6326




















6327
6328
6329
6330
6331
6332
6333
....
6344
6345
6346
6347
6348
6349
6350























6351
6352
6353
6354
6355
6356
6357
....
6364
6365
6366
6367
6368
6369
6370























6371
6372
6373
6374
6375
6376
6377
....
6392
6393
6394
6395
6396
6397
6398




























6399
6400
6401
6402
6403
6404
6405
....
6460
6461
6462
6463
6464
6465
6466






































6467
6468
6469
6470
6471
6472
6473
....
6484
6485
6486
6487
6488
6489
6490
























6491
6492
6493
6494
6495
6496
6497
....
6504
6505
6506
6507
6508
6509
6510






















6511
6512
6513
6514
6515
6516
6517
....
6553
6554
6555
6556
6557
6558
6559














































6560
6561
6562
6563
6564
6565




























6566
6567
6568
6569
6570
6571
6572
....
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
....
6678
6679
6680
6681
6682
6683
6684






































6685






































6686
6687
6688
6689
6690
6691
6692
....
6886
6887
6888
6889
6890
6891
6892
































6893
6894
6895
6896
6897
6898
6899
        {<doc xmlns:ns1="http://foo.bar" xmlns:ns2="http://foo.grill" xmlns:ns3="http://bar.grill"><e abc="" optional="this" ns3:optional="that" def="" ghi="" jkl="" mno="" pqr="" ns2:abc="" ns1:abc="" ns3:abc=""/></doc>}
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {MISSING_ATTRIBUTE abc {} 1 1 MISSING_ATTRIBUTE abc http://foo.bar 1 UNKNOWN_ATTRIBUTE abc http://bar.grill 1 MISSING_ATTRIBUTE abc {} 1 1 UNKNOWN_ATTRIBUTE abc http://bar.grill 1}




















test schema-12.1 {domvalidate} {
    tdom::schema s 
    s define {
        defelement addressBook {
            element card *
        }
................................................................................
        }
    }
    s event start doc
    set result [s info expected]
    s delete
    lsort $result
} {a b c musthave toplevel}





















test schema-17.6 {info expected} {
    tdom::schema s
    s prefixns {foo http://foo.bar}
    s define {
        defelement doc {
            choice ? {
................................................................................
    }
    s event start doc
    set result [s info expected]
    s delete
    lsort $result
} {a b c {musthave http://foo.bar} toplevel}
























test schema-17.7 {info expected} {
    tdom::schema s
    s prefixns {foo http://foo.bar}
    s define {
        defelement doc {
            mixed {
                element a
................................................................................
            }
            element aftermust
        }
    }
    s event start doc
    set result [s info expected]
    s delete























    lsort $result
} {a b c {musthave http://foo.bar} toplevel {{#text} {}}}

test schema-17.8 {info expected} {
    tdom::schema s
    s defelement doc {
        choice ? {
................................................................................
    lappend result {*}[lsort [s info expected]]
    s event start doc
    lappend result {*}[lsort [s info expected]]
    s event start c
    s event end
    lappend result {*}[lsort [s info expected]]
    s delete




























    set result
} {doc a b c doc a b c musthave toplevel musthave toplevel}

proc schema-17.9 {scmd} {
    global result
    lappend result {*}[lsort [$scmd info expected]]
}
................................................................................
        s defelement doc $def
        s event start doc
        lappend result {*}[lsort [s info expected]]
        s delete
    }
    set result
} {a b c a b c d a b c d}







































test schema-17.11 {info expected} {
    set defs {
        {
            group + {
                element c ?
                element a ?
................................................................................
        s event start b
        s event end
        set result [lsort [s info expected]]
        s delete
    }
    set result
} {a b c d}

























test schema-17.12 {info expected} {
    tdom::schema s
    s define {
        prefixns {ns1 http://foo.bar}
        defelement doc {
            element a
................................................................................
    s event start a
    s event end
    set result [lsort [s info expected]]
    s event start something
    s event end
    lappend result {*}[lsort [s info expected]]
    s delete






















    set result
} {{<any> {}} {<any> http://foo.bar} {<elementend> {}} b}

proc schema-17.13 {scmd args} {
    global fromReportCmd
    set fromReportCmd [lsort [$scmd info expected]]
}
................................................................................
        }
        s delete
        incr defnr
    }
    set result
} {0/0: 1 a 0/1: 1 0/2: 1 a 0/3: 1 0/4: 1 a 0/5: 1 {<elementend> {}} b 1/0: 1 a b 1/1: 1 b 1/2: 1 1/3: 1 1/4: 1 a b 1/5: 1 b 2/0: 1 2/1: 1 2/2: 1 2/3: 1 2/4: 1 {<elementend> {}} a b 2/5: 1 {<elementend> {}} b}















































proc schema-17.14 {scmd args} {
    global result
    lappend result {*}[lsort [$scmd info expected]]
}
test schema-17.14 {info expected} {
    set defs {




























        {
            group + {
                element c ?
                element a ?
                element b ?
            }
            tcl schema-17.14 [self]
................................................................................
        lappend result [s validate $xml]
        lappend result {*}$fromReportCmd
    }
    s delete
    set result
} {0 0 1 1 aaaa 1 b bb bbb bbbb 1}

test schema-17.16a {info expected} {
    tdom::schema s
    s defelement doc {
        element a
        group {
            group {
                group {
                    element aaaa *
                    element bbbb ?
                }
                element bbb ?
            }
            element bb ?
        }
        element b
................................................................................
    } {
        set fromReportCmd ""
        lappend result [s validate $xml]
        lappend result {*}$fromReportCmd
    }
    s delete
    set result






































} {0 0 1 1 aaaa b bb bbb bbbb 1 aaaa b bb bbb bbbb 1}







































test schema-17.16b {info expected} {
    tdom::schema s
    s defelement doc {
        element a
        group {
            group {
................................................................................
        <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 {






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







 







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







 







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







 







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







 







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







 







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







 







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







 







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







 







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






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







 







|






|







 







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







 







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







3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
....
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
....
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
....
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
....
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
....
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
....
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
....
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
....
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
....
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
....
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
....
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
        {<doc xmlns:ns1="http://foo.bar" xmlns:ns2="http://foo.grill" xmlns:ns3="http://bar.grill"><e abc="" optional="this" ns3:optional="that" def="" ghi="" jkl="" mno="" pqr="" ns2:abc="" ns1:abc="" ns3:abc=""/></doc>}
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {MISSING_ATTRIBUTE abc {} 1 1 MISSING_ATTRIBUTE abc http://foo.bar 1 UNKNOWN_ATTRIBUTE abc http://bar.grill 1 MISSING_ATTRIBUTE abc {} 1 1 UNKNOWN_ATTRIBUTE abc http://bar.grill 1}

proc schema-11.11 {scmd errType} {
    lappend ::result $errType
}
test schema-11.11 {attribute - required missing} {
    tdom::schema s
    s defelement doc {
        element a + {
            attribute mode
        }
    }
    s reportcmd schema-11.11
    set result ""
    set doc [dom parse <doc><a/></doc>]
    lappend result [s domvalidate $doc]
    $doc delete
    s delete
    set result
} {MISSING_ATTRIBUTE 1}

test schema-12.1 {domvalidate} {
    tdom::schema s 
    s define {
        defelement addressBook {
            element card *
        }
................................................................................
        }
    }
    s event start doc
    set result [s info expected]
    s delete
    lsort $result
} {a b c musthave toplevel}

test schema-17.5a {info expected} {
    tdom::schema s
    s define {
        defelement doc {
            choice ? {
                element a
                element c
                element b
            }
            element toplevel ?
            element musthave
            element aftermust
        }
    }
    s event start doc
    set result [s info expected -ignorematched]
    s delete
    lsort $result
} {a b c musthave toplevel}

test schema-17.6 {info expected} {
    tdom::schema s
    s prefixns {foo http://foo.bar}
    s define {
        defelement doc {
            choice ? {
................................................................................
    }
    s event start doc
    set result [s info expected]
    s delete
    lsort $result
} {a b c {musthave http://foo.bar} toplevel}

test schema-17.6a {info expected} {
    tdom::schema s
    s prefixns {foo http://foo.bar}
    s define {
        defelement doc {
            choice ? {
                element a
                element c
                element b
            }
            element toplevel ?
            namespace foo {
                element musthave
            }
            element aftermust
        }
    }
    s event start doc
    set result [s info expected -ignorematched]
    s delete
    lsort $result
} {a b c {musthave http://foo.bar} toplevel}

test schema-17.7 {info expected} {
    tdom::schema s
    s prefixns {foo http://foo.bar}
    s define {
        defelement doc {
            mixed {
                element a
................................................................................
            }
            element aftermust
        }
    }
    s event start doc
    set result [s info expected]
    s delete
    lsort $result
} {a b c {musthave http://foo.bar} toplevel {{#text} {}}}

test schema-17.7a {info expected} {
    tdom::schema s
    s prefixns {foo http://foo.bar}
    s define {
        defelement doc {
            mixed {
                element a
                element c
                element b
            }
            element toplevel ?
            namespace foo {
                element musthave
            }
            element aftermust
        }
    }
    s event start doc
    set result [s info expected -ignorematched]
    s delete
    lsort $result
} {a b c {musthave http://foo.bar} toplevel {{#text} {}}}

test schema-17.8 {info expected} {
    tdom::schema s
    s defelement doc {
        choice ? {
................................................................................
    lappend result {*}[lsort [s info expected]]
    s event start doc
    lappend result {*}[lsort [s info expected]]
    s event start c
    s event end
    lappend result {*}[lsort [s info expected]]
    s delete
    set result
} {doc a b c doc a b c musthave toplevel musthave toplevel}

test schema-17.8a {info expected} {
    tdom::schema s
    s defelement doc {
        choice ? {
            element a
            element c
            element b
        }
        element toplevel ?
        element musthave
        element aftermust
    }
    set result [s info expected -ignorematched]
    s define {
        foreach elm {a b c} {
            defelement $elm {}
        }
    }
    lappend result {*}[lsort [s info expected -ignorematched]]
    s event start doc
    lappend result {*}[lsort [s info expected -ignorematched]]
    s event start c
    s event end
    lappend result {*}[lsort [s info expected -ignorematched]]
    s delete
    set result
} {doc a b c doc a b c musthave toplevel musthave toplevel}

proc schema-17.9 {scmd} {
    global result
    lappend result {*}[lsort [$scmd info expected]]
}
................................................................................
        s defelement doc $def
        s event start doc
        lappend result {*}[lsort [s info expected]]
        s delete
    }
    set result
} {a b c a b c d a b c d}

test schema-17.10a {info expected interleave} {
    set defs {
        {
            interleave {
                element a ?
                element b
                element c ?
            }
            element d
        }
        {
            interleave {
                element a ?
                element b ?
                element c ?
            }
            element d
        }
        {
            interleave ? {
                element a ?
                element b
                element c ?
            }
            element d
        }
    }
    set result [list]
    foreach def $defs {
        tdom::schema s
        s defelement doc $def
        s event start doc
        lappend result {*}[lsort [s info expected -ignorematched]]
        s delete
    }
    set result
} {a b c a b c d a b c d}

test schema-17.11 {info expected} {
    set defs {
        {
            group + {
                element c ?
                element a ?
................................................................................
        s event start b
        s event end
        set result [lsort [s info expected]]
        s delete
    }
    set result
} {a b c d}

test schema-17.11a {info expected} {
    set defs {
        {
            group + {
                element c ?
                element a ?
                element b ?
            }
            element d
        }
    }
    set result [list]
    foreach def $defs {
        tdom::schema s
        s defelement doc $def
        s event start doc
        s event start b
        s event end
        set result [lsort [s info expected -ignorematched]]
        s delete
    }
    set result
} {d}

test schema-17.12 {info expected} {
    tdom::schema s
    s define {
        prefixns {ns1 http://foo.bar}
        defelement doc {
            element a
................................................................................
    s event start a
    s event end
    set result [lsort [s info expected]]
    s event start something
    s event end
    lappend result {*}[lsort [s info expected]]
    s delete
    set result
} {{<any> {}} {<any> http://foo.bar} {<elementend> {}} b}

test schema-17.12a {info expected} {
    tdom::schema s
    s define {
        prefixns {ns1 http://foo.bar}
        defelement doc {
            element a
            any
            any ns1 ?
            element b ?
        }
    }
    s event start doc
    s event start a
    s event end
    set result [lsort [s info expected -ignorematched]]
    s event start something
    s event end
    lappend result {*}[lsort [s info expected -ignorematched]]
    s delete
    set result
} {{<any> {}} {<any> http://foo.bar} {<elementend> {}} b}

proc schema-17.13 {scmd args} {
    global fromReportCmd
    set fromReportCmd [lsort [$scmd info expected]]
}
................................................................................
        }
        s delete
        incr defnr
    }
    set result
} {0/0: 1 a 0/1: 1 0/2: 1 a 0/3: 1 0/4: 1 a 0/5: 1 {<elementend> {}} b 1/0: 1 a b 1/1: 1 b 1/2: 1 1/3: 1 1/4: 1 a b 1/5: 1 b 2/0: 1 2/1: 1 2/2: 1 2/3: 1 2/4: 1 {<elementend> {}} a b 2/5: 1 {<elementend> {}} b}

proc schema-17.13a {scmd args} {
    global fromReportCmd
    set fromReportCmd [lsort [$scmd info expected -ignorematched]]
}
test schema-17.13a {info expected} {
    set defs {
        {
            element a
            element b ?
        }
        {
            element a ?
            element b
        }
        {
            element a ?
            element b ?
        }
    }
    set xmlinput {
        <doc/>
        <doc><a/></doc>
        <doc><b/></doc>
        <doc><a/><b/></doc>
        <doc><unknown/></doc>
        <doc><a/><unknown/></doc>
    }
    set result [list]
    set defnr 0
    foreach def $defs {
        tdom::schema s
        s defelement doc $def
        s reportcmd schema-17.13
        set xmlnr 0
        foreach xml $xmlinput {
            set fromReportCmd ""
            lappend result $defnr/$xmlnr: [s validate $xml errMsg]
            lappend result {*}$fromReportCmd
            incr xmlnr
        }
        s delete
        incr defnr
    }
    set result
} {0/0: 1 a 0/1: 1 0/2: 1 a 0/3: 1 0/4: 1 a 0/5: 1 {<elementend> {}} b 1/0: 1 a b 1/1: 1 b 1/2: 1 1/3: 1 1/4: 1 a b 1/5: 1 b 2/0: 1 2/1: 1 2/2: 1 2/3: 1 2/4: 1 {<elementend> {}} a b 2/5: 1 {<elementend> {}} b}

proc schema-17.14 {scmd args} {
    global result
    lappend result {*}[lsort [$scmd info expected]]
}
test schema-17.14 {info expected} {
    set defs {
        {
            group + {
                element c ?
                element a ?
                element b ?
            }
            tcl schema-17.14 [self]
            element d
        }
    }
    set result [list]
    foreach def $defs {
        tdom::schema s
        s reportcmd schema-17.14
        s defelement doc $def
        s event start doc
        s event start unknownElement
        s delete
    }
    set result
} {a b c d a b c d}

proc schema-17.14a {scmd args} {
    global result
    lappend result {*}[lsort [$scmd info expected -ignorematched]]
}
test schema-17.14a {info expected} {
    set defs {
        {
            group + {
                element c ?
                element a ?
                element b ?
            }
            tcl schema-17.14 [self]
................................................................................
        lappend result [s validate $xml]
        lappend result {*}$fromReportCmd
    }
    s delete
    set result
} {0 0 1 1 aaaa 1 b bb bbb bbbb 1}

test schema-17.16_1{info expected} {
    tdom::schema s
    s defelement doc {
        element a
        group {
            group {
                group {
                    element aaaa
                    element bbbb ?
                }
                element bbb ?
            }
            element bb ?
        }
        element b
................................................................................
    } {
        set fromReportCmd ""
        lappend result [s validate $xml]
        lappend result {*}$fromReportCmd
    }
    s delete
    set result
} {0 0 1 1 aaaa 1 b bb bbb bbbb 1}

test schema-17.16a {info expected} {
    tdom::schema s
    s defelement doc {
        element a
        group {
            group {
                group {
                    element aaaa *
                    element bbbb ?
                }
                element bbb ?
            }
            element bb ?
        }
        element b
    }
    set result [list]
    foreach xml {
        <doc><a/></doc>
        <doc><a/><aaaa/></doc>
        <doc><a/><aaaa/><b/></doc>
    } {
        lappend result [s validate $xml]
    }
    s reportcmd schema-17.13a
    foreach xml {
        <doc><a/></doc>
        <doc><a/><aaaa/></doc>
        <doc><a/><aaaa/><b/></doc>
    } {
        set fromReportCmd ""
        lappend result [s validate $xml]
        lappend result {*}$fromReportCmd
    }
    s delete
    set result
} {0 0 1 1 aaaa b bb bbb bbbb 1 b bb bbb bbbb 1}

test schema-17.16a_1 {info expected} {
    tdom::schema s
    s defelement doc {
        element a
        group {
            group {
                group {
                    element aaaa *
                    element bbbb ?
                }
                element bbb ?
            }
            element bb ?
        }
        element b
    }
    set result [list]
    foreach xml {
        <doc><a/></doc>
        <doc><a/><aaaa/></doc>
        <doc><a/><aaaa/><b/></doc>
    } {
        lappend result [s validate $xml]
    }
    s reportcmd schema-17.13a
    foreach xml {
        <doc><a/></doc>
        <doc><a/><aaaa/></doc>
        <doc><a/><aaaa/><b/></doc>
    } {
        set fromReportCmd ""
        lappend result [s validate $xml]
        lappend result {*}$fromReportCmd
    }
    s delete
    set result
} {0 0 1 1 aaaa b bb bbb bbbb 1 b bb bbb bbbb 1}

test schema-17.16b {info expected} {
    tdom::schema s
    s defelement doc {
        element a
        group {
            group {
................................................................................
        <doc><a/><b/></doc>
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {{} 1 1 1 {fo bar baz} 1 {} 1}

proc schema-17.21 {scmd errorInfo} {
    lappend ::result [$scmd info expected]
}
test schema-17.21 {info expected} {
    tdom::schema s
    s defelement doc {
        element a + {}
        element b ! {}
    }
    s reportcmd schema-17.21
    set result ""
    lappend result [s validate {<doc><a/><unexpected/></doc>}]
    s delete
    set result
} {{a b} 1}

proc schema-17.21a {scmd errorInfo} {
    lappend ::result [$scmd info expected -ignorematched]
}
test schema-17.21a {info expected} {
    tdom::schema s
    s defelement doc {
        element a + {}
        element b ! {}
    }
    s reportcmd schema-17.21a
    set result ""
    lappend result [s validate {<doc><a/><unexpected/></doc>}]
    s delete
    set result
} {b 1}

proc schema-18 {args} {
    lappend ::result {*}$args
}
test schema-18.1 {reportcmd} {
    tdom::schema s
    s define {