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

Overview
Comment:Recovery is hard. For several reasons.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wip
Files: files | file ages | folders
SHA3-256: bd90f4a8d46b2b5b8d4785b58bb6c112caa1c427286430a8f15d53f047cc4bdb
User & Date: rolf 2019-10-17 00:41:48
Context
2019-10-23
09:25
Merged from schema. check-in: 3c16fd1ab1 user: rolf tags: wip
2019-10-17
00:41
Recovery is hard. For several reasons. check-in: bd90f4a8d4 user: rolf tags: wip
2019-10-12
13:29
Save work. check-in: 8d9da46798 user: rolf tags: wip
Changes

Changes to generic/schema.c.

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89












































90
91
92
93
94
95
96
..
98
99
100
101
102
103
104




105
106




107
108
109
110
111
112
113
...
249
250
251
252
253
254
255

256
257
258
259
260
261
262
...
894
895
896
897
898
899
900




















































901
902
903
904
905
906
907
...
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
....
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
....
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
....
1332
1333
1334
1335
1336
1337
1338





1339
1340
1341
1342
1343
1344






1345
1346
1347
1348
1349






1350
1351
1352
1353
1354
1355
1356
....
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492

1493

1494
1495
1496
1497
1498
1499
1500
....
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595

1596
1597
1598
1599
1600
1601

1602
1603
1604

1605
1606
1607
1608
1609
1610
1611

1612

1613
1614
1615
1616
1617
1618
1619
....
1638
1639
1640
1641
1642
1643
1644

1645
1646

1647
1648
1649
1650

1651
1652
1653
1654
1655
1656
1657
....
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
....
1833
1834
1835
1836
1837
1838
1839

1840

1841
1842
1843
1844
1845
1846
1847
1848
1849

1850
1851
1852
1853
1854
1855
1856
1857
1858

1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874

1875
1876
1877
1878
1879
1880
1881
....
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
....
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981





1982
1983
1984
1985
1986
1987
1988
....
2007
2008
2009
2010
2011
2012
2013
2014

2015
2016
2017

2018
2019
2020
2021

2022
2023
2024
2025




2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039




2040
2041
2042
2043
2044
2045
2046
2047
....
2057
2058
2059
2060
2061
2062
2063
2064

2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075




2076
2077
2078
2079
2080
2081
2082
2083
2084



2085
2086
2087
2088
2089
2090
2091
2092
....
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
/*----------------------------------------------------------------------------
|   Local typedefs
|
\---------------------------------------------------------------------------*/

typedef struct
{
    SchemaData *sdata;
    Tcl_Interp    *interp;
    XML_Parser     parser;
    Tcl_DString   *cdata;
    int            onlyWhiteSpace;
    char          *uri;
    int            maxUriLen;
} ValidateMethodData;













































/*----------------------------------------------------------------------------
|   domKeyConstraint related flage
|
\---------------------------------------------------------------------------*/

#define DKC_FLAG_IGNORE_EMPTY_FIELD_SET 1

................................................................................
|   Macros
|
\---------------------------------------------------------------------------*/
#define TMALLOC(t) (t*)MALLOC(sizeof(t))

#define SetResult(str) Tcl_ResetResult(interp); \
                     Tcl_SetStringObj(Tcl_GetObjResult(interp), (str), -1)




#define SetResult3(str1,str2,str3) Tcl_ResetResult(interp);     \
                     Tcl_AppendResult(interp, (str1), (str2), (str3), NULL)




#define SetIntResult(i) Tcl_ResetResult(interp);                        \
                     Tcl_SetIntObj(Tcl_GetObjResult(interp), (i))
#define SetBooleanResult(i) Tcl_ResetResult(interp); \
                     Tcl_SetBooleanObj(Tcl_GetObjResult(interp), (i))

#define SPACE(c) ((c) == ' ' || (c) == '\n' || (c) == '\t' || (c) == '\r')
    
................................................................................
#define getContext(cp, ac, hm)        \
    cp = se->pattern;                 \
    ac = se->activeChild;             \
    hm = se->hasMatched;


#define updateStack(se,cp,ac)                     \

    if (maxOne (cp->quants[ac])) {                \
        se->activeChild = ac + 1;                 \
        se->hasMatched = 0;                       \
    } else {                                      \
        se->activeChild = ac;                     \
        se->hasMatched = 1;                       \
    }
................................................................................
    popStack (sdata);
    /* cp is still the pattern from stack top before the popStack */
    if (cp->type != SCHEMA_CTYPE_NAME) {
        finalizeElement (sdata, sdata->stack->activeChild + 1);
    }
}






















































static int 
recover (
    Tcl_Interp *interp,
    SchemaData *sdata,
    const char *errType,
    int len,
................................................................................
    int popStack,
    int ac
    )
{
    Tcl_Obj *cmdPtr;
    int rc;

    if (!sdata->reportCmd) return 0;
    cmdPtr = Tcl_DuplicateObj (sdata->reportCmd);
    Tcl_IncrRefCount(cmdPtr);
    Tcl_ListObjAppendElement (interp, cmdPtr,
                              sdata->self);
    Tcl_ListObjAppendElement (
        interp, cmdPtr,
        Tcl_NewStringObj (errType, len)
................................................................................
                if (rc == -1) mayskip = 1;
                break;

            case SCHEMA_CTYPE_KEYSPACE_END:
                candidate->keySpace->active--;
                if (!candidate->keySpace->active) {
                    if (candidate->keySpace->unknownIDrefs) {
                        if (!recover (interp, sdata, S("UNKNOWN_KEYREF"),
                                      0, 0)) {
                            return 0;
                        }
                        candidate->keySpace->unknownIDrefs = 0;
                    }
                    Tcl_DeleteHashTable (&candidate->keySpace->ids);
                }
................................................................................
    }

    DBG(
        fprintf (stderr, "probeElement: look if '%s' in ns '%s' match\n",
                 name, (char *)namespace);
        );

    /* This is problematic. If feeded with continuously new namespaces */
    if (namespace) {
        h = Tcl_FindHashEntry (&sdata->namespace, namespace);
    } else {
        h = NULL;
    }
    if (h) {
        namespacePtr = Tcl_GetHashKey (&sdata->namespace, h);
................................................................................
        }
    }
    
    if (sdata->validationState == VALIDATION_READY) {
        /* The root of the tree to check. */
        if (sdata->start) {
            if (strcmp (name, sdata->start) != 0) {





                SetResult ("Root element doesn't match");
                return TCL_ERROR;
            }
            if (namespace) {
                if (!sdata->startNamespace||
                    strcmp (namespace, sdata->startNamespace) != 0) {






                    SetResult ("Root element namespace doesn't match");
                    return TCL_ERROR;
                }
            } else {
                if (sdata->startNamespace) {






                    SetResult ("Root element namespace doesn't match");
                    return TCL_ERROR;
                }
            }
        }
    }
    if (h) {
................................................................................
            }
            if (strcmp (ln, cp->attrs[i]->name) == 0) {
                found = 1;
                if (cp->attrs[i]->cp) {
                    if (!checkText (interp, cp->attrs[i]->cp,
                                    (char *) atPtr[1])) {
                        if (!recover (interp, sdata,
                                      S("WRONG_ATTRIBUTE_VALUE"), 0, 0)) {
                            if (nsatt) namespace[j] = '\xFF';
                            SetResult3 ("Attribute value doesn't match for "
                                        "attribute '", atPtr[0], "'");
                            return TCL_ERROR;
                        }
                    }
                }
                if (cp->attrs[i]->required) reqAttr++;
                break;
            }
        }
        if (nsatt) namespace[j] = '\xFF';
        if (!found) {
            if (!recover (interp, sdata, S("UNKNOWN_ATTRIBUTE"), 0, 0)) {
                SetResult3 ("Unknown attribute \"", atPtr[0], "\"");
                return TCL_ERROR;
            }
        }
    }
    if (reqAttr != cp->numReqAttr) {
        /* Lookup the missing attribute(s) */

        SetResult ("Missing mandatory attribute(s):");

        for (i = 0; i < cp->numAttr; i++) {
            if (!cp->attrs[i]->required) continue;
            found = 0;
            for (atPtr = (char **) attr; atPtr[0] && atPtr[1]; atPtr += 2) {
                if (cp->attrs[i]->namespace) {
                    ln = atPtr[0];
                    j = 0;
................................................................................
                if (cp->attrs[i]->namespace) continue;
            }
            if (strcmp (ln, cp->attrs[i]->name) == 0) {
                if (cp->attrs[i]->cp) {
                    if (!checkText (interp, cp->attrs[i]->cp,
                                    (char *) atPtr->nodeValue)) {
                        if (!recover (interp, sdata,
                                      S("WRONG_ATTRIBUTE_VALUE"), 0, 0)) {
                            SetResult3 ("Attribute value doesn't match for "
                                        "attribute '", ln, "'");
                            return TCL_ERROR;
                        }
                    }
                }
                found = 1;
                if (cp->attrs[i]->required) reqAttr++;
                break;
            }
        }
        if (!found) {
            if (!recover (interp, sdata, S("UNKNOWN_ATTRIBUTE"), 0, 0)) {

                if (ns) {
                    SetResult ("Unknown attribute \"");
                    Tcl_AppendResult (interp, ns, ":", atPtr->nodeName,
                                      "\"");
                } else {
                    SetResult3 ("Unknown attribute \"", atPtr->nodeName, "\"");

                }
                sdata->validationState = VALIDATION_ERROR;
                return TCL_ERROR;

            }
        }
    nextAttr:
        atPtr = atPtr->nextSibling;
    }
    if (reqAttr != cp->numReqAttr) {
        /* Lookup the missing attribute(s) */

        SetResult ("Missing mandatory attribute(s):");

        for (i = 0; i < cp->numAttr; i++) {
            if (!cp->attrs[i]->required) continue;
            found = 0;
            atPtr = attr;
            while (atPtr) {
                if (cp->attrs[i]->namespace) {
                    if (!atPtr->namespace) goto nextAttr2;
................................................................................
                    break;
                }
            nextAttr2:
                atPtr = atPtr->nextSibling;
            }
            if (!found) {
                if (!recover (interp, sdata, S("MISSING_ATTRIBUTE"), 0, 0)) {

                    if (cp->attrs[i]->namespace) {
                        Tcl_AppendResult (interp, " ", cp->attrs[i]->namespace,

                                          ":", cp->attrs[i]->name, NULL);
                    } else {
                        Tcl_AppendResult (interp, " ", cp->attrs[i]->name,
                                          NULL);

                    }
                }
            }
        }
        if (!sdata->reportCmd) {
            sdata->validationState = VALIDATION_ERROR;
            return TCL_ERROR;
................................................................................
            }
            
            switch (cp->content[ac]->type) {
            case SCHEMA_CTYPE_KEYSPACE_END:
                cp->content[ac]->keySpace->active--;
                if (!cp->content[ac]->keySpace->active) {
                    if (cp->content[ac]->keySpace->unknownIDrefs) {
                        if (!recover (interp, sdata, S("UNKNOWN_KEYREF"), 0, 0)) {
                            return 0;
                        }
                        cp->content[ac]->keySpace->unknownIDrefs = 0;
                    }
                    Tcl_DeleteHashTable (&cp->content[ac]->keySpace->ids);
                }
                break;
................................................................................
{
    Tcl_HashEntry *h, *h1;
    Tcl_HashSearch search, search1;
    int haveErrMsg = 0;
    SchemaDocKey *dk;

    /* TODO: add recovering */

    if (sdata->unknownIDrefs) {

        haveErrMsg = 1;
        SetResult ("References to unknown IDs:");
        for (h = Tcl_FirstHashEntry (&sdata->ids, &search);
             h != NULL;
             h = Tcl_NextHashEntry (&search)) {
            if (Tcl_GetHashValue (h) == 0) {
                Tcl_AppendResult (interp, " '",
                                  Tcl_GetHashKey (&sdata->ids, h),
                                  "'", NULL);

            }
        }
    }
    if (sdata->idTables.numEntries) {
        for (h = Tcl_FirstHashEntry (&sdata->idTables, &search);
             h != NULL;
             h = Tcl_NextHashEntry (&search)) {
            dk = Tcl_GetHashValue (h);
            if (dk->unknownIDrefs) {

                if (haveErrMsg) {
                    Tcl_AppendResult (interp, "\n", NULL);
                } else {
                    haveErrMsg = 1;
                }
                Tcl_AppendResult (interp,
                                  "References to unknown IDs in ID space '",
                                  Tcl_GetHashKey (&sdata->idTables, h),
                                  "':", NULL);
                for (h1 = Tcl_FirstHashEntry (&dk->ids, &search1);
                     h1 != NULL;
                     h1 = Tcl_NextHashEntry (&search1)) {
                    if (Tcl_GetHashValue (h1) == 0) {
                        Tcl_AppendResult (interp, " '",
                                          Tcl_GetHashKey (&dk->ids, h1),
                                          "'", NULL);

                    }
                }
            }
        }
    }
    if (haveErrMsg) {
        sdata->validationState = VALIDATION_ERROR;
................................................................................
        popStack (sdata);
        if (sdata->stack == NULL) {
            /* End of the first pattern (the tree root) without error. */
            /* Check for unknown ID references */
            if (!checkDocKeys (interp, sdata)) {
                return TCL_ERROR;
            }
            /*  We have successfully ended validation */
            sdata->validationState = VALIDATION_FINISHED;
        }
        DBG(
            fprintf(stderr, "probeElementEnd: _CAN_ end here.\n");
            serializeStack (sdata);
            );
        return TCL_OK;
    }
    SetResult ("Missing mandatory content");
    sdata->validationState = VALIDATION_ERROR;
    DBG(
        fprintf(stderr, "probeElementEnd: CAN'T end here.\n");
        serializeStack (sdata);
        );
    return TCL_ERROR;
}
................................................................................
                candidate = cp->content[ac];
                switch (candidate->type) {
                case SCHEMA_CTYPE_TEXT:
                    if (checkText (interp, candidate, text)) {
                        updateStack (se, cp, ac);
                        return 1;
                    }
                    if (!sdata->evalError) {
                        SetResult ("Invalid text content");
                    }
                    updateStack (se, cp, ac);





                    return 0;

                case SCHEMA_CTYPE_CHOICE:
                    if (candidate->flags & MIXED_CONTENT) {
                        updateStack (se, cp, ac);
                        return 1;
                    }
................................................................................
                                updateStack (se, cp, ac);
                                return 1;
                            }
                            popStack (sdata);
                            break;

                        case SCHEMA_CTYPE_VIRTUAL:
                            Tcl_Panic ("Virtual constrain in MIXED or CHOICE");

                            
                        case SCHEMA_CTYPE_CHOICE:
                            Tcl_Panic ("MIXED or CHOICE child of MIXED or CHOICE");


                        case SCHEMA_CTYPE_KEYSPACE_END:
                        case SCHEMA_CTYPE_KEYSPACE:
                            Tcl_Panic ("Keyspace constrain in MIXED or CHOICE");

                            
                        }
                    }
                    if (mustMatch (cp->quants[ac], hm)) {




                        SetResult ("Unexpected text content");
                        return 0;
                    }
                    break;

                case SCHEMA_CTYPE_INTERLEAVE:
                case SCHEMA_CTYPE_PATTERN:
                    pushToStack (sdata, candidate, ac);
                    if (matchText (interp, sdata, text)) {
                        updateStack (se, cp, ac);
                        return 1;
                    }
                    popStack (sdata);
                    if (mustMatch (cp->quants[ac], hm)) {




                        SetResult ("Unexpected text content");
                        return 0;
                    }
                    break;

                case SCHEMA_CTYPE_VIRTUAL:
                    if (!evalVirtual (interp, sdata, ac)) return 0;
                    break;
................................................................................
                    }
                    break;
                    
                case SCHEMA_CTYPE_KEYSPACE_END:
                    cp->content[ac]->keySpace->active--;
                    if (!cp->content[ac]->keySpace->active) {
                        if (cp->content[ac]->keySpace->unknownIDrefs) {
                            if (!recover (interp, sdata, S("UNKNOWN_KEYREF"), 0, 0)) {

                                return 0;
                            }
                            cp->content[ac]->keySpace->unknownIDrefs = 0;
                        }
                        Tcl_DeleteHashTable (&cp->content[ac]->keySpace->ids);
                    }
                    break;
                    
                case SCHEMA_CTYPE_NAME:
                case SCHEMA_CTYPE_ANY:
                    if (mustMatch (cp->quants[ac], hm)) {




                        SetResult ("Unexpected text content");
                        return 0;
                    }
                    break;

                }
                ac++;
            }
            if (isName) {



                SetResult ("Unexpected text content");
                return 0;
            }
            popStack (sdata);
            continue;

        case SCHEMA_CTYPE_KEYSPACE:
        case SCHEMA_CTYPE_KEYSPACE_END:
................................................................................
            break;
        }
        if (only_whites)  return TCL_OK;
        if (matchText (interp, sdata, text)) {
            return TCL_OK;
        }
    }
    if (recover (interp, sdata, S("WRONG_VALUE"), 0, 0)) {
        return TCL_OK;
    }
    if (!sdata->evalError) {
        SetResult ("Text content doesn't match");
    }
    return TCL_ERROR;
}

static void







|








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







 







>
>
>
>


>
>
>
>







 







>







 







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







 







|







 







|







 







<







 







>
>
>
>
>






>
>
>
>
>
>





>
>
>
>
>
>







 







|

|
|











|






>
|
>







 







|
|
|











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







>
|
>







 







>
|
|
>
|
|
|
|
>







 







|







 







>

>
|
|
|
|
|
|
|
|
|
>









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







 







|








|







 







|
|
<
|
>
>
>
>
>







 







|
>


|
>



|
>




>
>
>
>
|













>
>
>
>
|







 







|
>











>
>
>
>
|








>
>
>
|







 







<
<
<







74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
...
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
...
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
...
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
....
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
....
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
....
1400
1401
1402
1403
1404
1405
1406

1407
1408
1409
1410
1411
1412
1413
....
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
....
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
....
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
....
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
....
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
....
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
....
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
....
2107
2108
2109
2110
2111
2112
2113
2114
2115

2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
....
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
....
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
....
2344
2345
2346
2347
2348
2349
2350



2351
2352
2353
2354
2355
2356
2357
/*----------------------------------------------------------------------------
|   Local typedefs
|
\---------------------------------------------------------------------------*/

typedef struct
{
    SchemaData    *sdata;
    Tcl_Interp    *interp;
    XML_Parser     parser;
    Tcl_DString   *cdata;
    int            onlyWhiteSpace;
    char          *uri;
    int            maxUriLen;
} ValidateMethodData;

typedef enum {
    DOM_KEYCONSTRAINT,
    INVALID_DOM_KEYCONSTRAINT,
    MISSING_ANY,
    MISSING_ATTRIBUTE,
    MISSING_CP,
    MISSING_ELEMENT,
    MISSING_ONE_OF_CHOICE,
    MISSING_ONE_OF_INTERLEAVE,
    MISSING_TEXT,
    UNEXPECTED_DOCUMENT_ELEMENT,
    UNEXPECTED_DOCUMENT_ELEMENT_NAMESPACE,
    UNEXPECTED_ELEMENT,
    UNKNOWN_ATTRIBUTE,
    INVALID_KEYREF,
    UNKNOWN_ROOT_ELEMENT,
    UNKOWN_GLOBAL_ID,
    UNKOWN_ID,
    INVALID_ATTRIBUTE_VALUE,
    INVALID_VALUE
} ValidationErrorType;

static char *ValidationErrorType2str[] = {
    "DOM_KEYCONSTRAINT",
    "INVALID_DOM_KEYCONSTRAINT",
    "MISSING_ANY",
    "MISSING_ATTRIBUTE",
    "MISSING_CP",
    "MISSING_ELEMENT",
    "MISSING_ONE_OF_CHOICE",
    "MISSING_ONE_OF_INTERLEAVE",
    "MISSING_TEXT",
    "UNEXPECTED_DOCUMENT_ELEMENT",
    "UNEXPECTED_DOCUMENT_ELEMENT_NAMESPACE",
    "UNEXPECTED_ELEMENT",
    "UNKNOWN_ATTRIBUTE",
    "INVALID_KEYREF",
    "UNKNOWN_ROOT_ELEMENT",
    "UNKOWN_GLOBAL_ID",
    "UNKOWN_ID",
    "INVALID_ATTRIBUTE_VALUE",
    "INVALID_VALUE"
};
    
/*----------------------------------------------------------------------------
|   domKeyConstraint related flage
|
\---------------------------------------------------------------------------*/

#define DKC_FLAG_IGNORE_EMPTY_FIELD_SET 1

................................................................................
|   Macros
|
\---------------------------------------------------------------------------*/
#define TMALLOC(t) (t*)MALLOC(sizeof(t))

#define SetResult(str) Tcl_ResetResult(interp); \
                     Tcl_SetStringObj(Tcl_GetObjResult(interp), (str), -1)
#define SetResultV(str) if (!sdata->evalError) { \
        Tcl_ResetResult(interp);                                        \
        Tcl_SetStringObj(Tcl_GetObjResult(interp), (str), -1);          \
    }
#define SetResult3(str1,str2,str3) Tcl_ResetResult(interp);     \
                     Tcl_AppendResult(interp, (str1), (str2), (str3), NULL)
#define SetResult3V(str1,str2,str3) if (!sdata->evalError) {            \
        Tcl_ResetResult(interp);                                        \
        Tcl_AppendResult(interp, (str1), (str2), (str3), NULL);         \
    }
#define SetIntResult(i) Tcl_ResetResult(interp);                        \
                     Tcl_SetIntObj(Tcl_GetObjResult(interp), (i))
#define SetBooleanResult(i) Tcl_ResetResult(interp); \
                     Tcl_SetBooleanObj(Tcl_GetObjResult(interp), (i))

#define SPACE(c) ((c) == ' ' || (c) == '\n' || (c) == '\t' || (c) == '\r')
    
................................................................................
#define getContext(cp, ac, hm)        \
    cp = se->pattern;                 \
    ac = se->activeChild;             \
    hm = se->hasMatched;


#define updateStack(se,cp,ac)                     \
    se->startChild = ac;                          \
    if (maxOne (cp->quants[ac])) {                \
        se->activeChild = ac + 1;                 \
        se->hasMatched = 0;                       \
    } else {                                      \
        se->activeChild = ac;                     \
        se->hasMatched = 1;                       \
    }
................................................................................
    popStack (sdata);
    /* cp is still the pattern from stack top before the popStack */
    if (cp->type != SCHEMA_CTYPE_NAME) {
        finalizeElement (sdata, sdata->stack->activeChild + 1);
    }
}

static int 
recoverex (
    Tcl_Interp *interp,
    SchemaData *sdata,
    ValidationErrorType errorType
    )
{
    Tcl_Obj *cmdPtr;
    int rc;

    if (!sdata->reportCmd || sdata->evalError) return 0;
    cmdPtr = Tcl_DuplicateObj (sdata->reportCmd);
    Tcl_IncrRefCount(cmdPtr);
    Tcl_ListObjAppendElement (interp, cmdPtr,
                              sdata->self);
    Tcl_ListObjAppendElement (
        interp, cmdPtr,
        Tcl_NewStringObj (ValidationErrorType2str[errorType], -1)
        );
    sdata->currentEvals++;
    rc = Tcl_EvalObjEx (interp, cmdPtr,
                        TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
    sdata->currentEvals--;
    Tcl_DecrRefCount (cmdPtr);
    if (rc != TCL_OK) {
        sdata->evalError = 1;
        return 0;
    }
    switch (errorType) {
    case DOM_KEYCONSTRAINT:
    case INVALID_DOM_KEYCONSTRAINT:
    case MISSING_ANY:
    case MISSING_ATTRIBUTE:
    case MISSING_CP:
    case MISSING_ELEMENT:
    case MISSING_ONE_OF_CHOICE:
    case MISSING_ONE_OF_INTERLEAVE:
    case MISSING_TEXT:
    case UNEXPECTED_DOCUMENT_ELEMENT:
    case UNEXPECTED_DOCUMENT_ELEMENT_NAMESPACE:
    case UNEXPECTED_ELEMENT:
    case UNKNOWN_ATTRIBUTE:
    case INVALID_KEYREF:
    case UNKNOWN_ROOT_ELEMENT:
    case UNKOWN_GLOBAL_ID:
    case UNKOWN_ID:
    case INVALID_ATTRIBUTE_VALUE:
    case INVALID_VALUE:
        break;
    }
    return 0;
}

static int 
recover (
    Tcl_Interp *interp,
    SchemaData *sdata,
    const char *errType,
    int len,
................................................................................
    int popStack,
    int ac
    )
{
    Tcl_Obj *cmdPtr;
    int rc;

    if (!sdata->reportCmd || sdata->evalError) return 0;
    cmdPtr = Tcl_DuplicateObj (sdata->reportCmd);
    Tcl_IncrRefCount(cmdPtr);
    Tcl_ListObjAppendElement (interp, cmdPtr,
                              sdata->self);
    Tcl_ListObjAppendElement (
        interp, cmdPtr,
        Tcl_NewStringObj (errType, len)
................................................................................
                if (rc == -1) mayskip = 1;
                break;

            case SCHEMA_CTYPE_KEYSPACE_END:
                candidate->keySpace->active--;
                if (!candidate->keySpace->active) {
                    if (candidate->keySpace->unknownIDrefs) {
                        if (!recover (interp, sdata, S("INVALID_KEYREF"),
                                      0, 0)) {
                            return 0;
                        }
                        candidate->keySpace->unknownIDrefs = 0;
                    }
                    Tcl_DeleteHashTable (&candidate->keySpace->ids);
                }
................................................................................
    }

    DBG(
        fprintf (stderr, "probeElement: look if '%s' in ns '%s' match\n",
                 name, (char *)namespace);
        );


    if (namespace) {
        h = Tcl_FindHashEntry (&sdata->namespace, namespace);
    } else {
        h = NULL;
    }
    if (h) {
        namespacePtr = Tcl_GetHashKey (&sdata->namespace, h);
................................................................................
        }
    }
    
    if (sdata->validationState == VALIDATION_READY) {
        /* The root of the tree to check. */
        if (sdata->start) {
            if (strcmp (name, sdata->start) != 0) {
                if (recover (interp, sdata, S("UNEXPECTED_DOCUMENT_ELEMENT"),
                             0, 0)) {
                    sdata->validationState = VALIDATION_FINISHED;
                    return TCL_OK;
                }
                SetResult ("Root element doesn't match");
                return TCL_ERROR;
            }
            if (namespace) {
                if (!sdata->startNamespace||
                    strcmp (namespace, sdata->startNamespace) != 0) {
                    if (recover (interp, sdata,
                                 S("UNEXPECTED_DOCUMENT_ELEMENT_NAMESPACE"),
                                 0, 0)) {
                        sdata->validationState = VALIDATION_FINISHED;
                        return TCL_OK;
                    }
                    SetResult ("Root element namespace doesn't match");
                    return TCL_ERROR;
                }
            } else {
                if (sdata->startNamespace) {
                    if (recover (interp, sdata,
                                 S("UNEXPECTED_DOCUMENT_ELEMENT_NAMESPACE"),
                                 0, 0)) {
                        sdata->validationState = VALIDATION_FINISHED;
                        return TCL_OK;
                    }
                    SetResult ("Root element namespace doesn't match");
                    return TCL_ERROR;
                }
            }
        }
    }
    if (h) {
................................................................................
            }
            if (strcmp (ln, cp->attrs[i]->name) == 0) {
                found = 1;
                if (cp->attrs[i]->cp) {
                    if (!checkText (interp, cp->attrs[i]->cp,
                                    (char *) atPtr[1])) {
                        if (!recover (interp, sdata,
                                      S("INVALID_ATTRIBUTE_VALUE"), 0, 0)) {
                            if (nsatt) namespace[j] = '\xFF';
                            SetResult3V ("Attribute value doesn't match for "
                                         "attribute '", atPtr[0], "'");
                            return TCL_ERROR;
                        }
                    }
                }
                if (cp->attrs[i]->required) reqAttr++;
                break;
            }
        }
        if (nsatt) namespace[j] = '\xFF';
        if (!found) {
            if (!recover (interp, sdata, S("UNKNOWN_ATTRIBUTE"), 0, 0)) {
                SetResult3V ("Unknown attribute \"", atPtr[0], "\"");
                return TCL_ERROR;
            }
        }
    }
    if (reqAttr != cp->numReqAttr) {
        /* Lookup the missing attribute(s) */
        if (!sdata->evalError) {
            SetResult ("Missing mandatory attribute(s):");
        }
        for (i = 0; i < cp->numAttr; i++) {
            if (!cp->attrs[i]->required) continue;
            found = 0;
            for (atPtr = (char **) attr; atPtr[0] && atPtr[1]; atPtr += 2) {
                if (cp->attrs[i]->namespace) {
                    ln = atPtr[0];
                    j = 0;
................................................................................
                if (cp->attrs[i]->namespace) continue;
            }
            if (strcmp (ln, cp->attrs[i]->name) == 0) {
                if (cp->attrs[i]->cp) {
                    if (!checkText (interp, cp->attrs[i]->cp,
                                    (char *) atPtr->nodeValue)) {
                        if (!recover (interp, sdata,
                                      S("INVALID_ATTRIBUTE_VALUE"), 0, 0)) {
                            SetResult3V ("Attribute value doesn't match for "
                                         "attribute '", ln, "'");
                            return TCL_ERROR;
                        }
                    }
                }
                found = 1;
                if (cp->attrs[i]->required) reqAttr++;
                break;
            }
        }
        if (!found) {
            if (!recover (interp, sdata, S("UNKNOWN_ATTRIBUTE"), 0, 0)) {
                if (!sdata->evalError) {
                    if (ns) {
                        SetResult ("Unknown attribute \"");
                        Tcl_AppendResult (interp, ns, ":", atPtr->nodeName,
                                          "\"");
                    } else {
                        SetResult3 ("Unknown attribute \"", atPtr->nodeName,
                                    "\"");
                    }
                    sdata->validationState = VALIDATION_ERROR;
                    return TCL_ERROR;
                }
            }
        }
    nextAttr:
        atPtr = atPtr->nextSibling;
    }
    if (reqAttr != cp->numReqAttr) {
        /* Lookup the missing attribute(s) */
        if (!sdata->evalError) {
            SetResult ("Missing mandatory attribute(s):");
        }
        for (i = 0; i < cp->numAttr; i++) {
            if (!cp->attrs[i]->required) continue;
            found = 0;
            atPtr = attr;
            while (atPtr) {
                if (cp->attrs[i]->namespace) {
                    if (!atPtr->namespace) goto nextAttr2;
................................................................................
                    break;
                }
            nextAttr2:
                atPtr = atPtr->nextSibling;
            }
            if (!found) {
                if (!recover (interp, sdata, S("MISSING_ATTRIBUTE"), 0, 0)) {
                    if (!sdata->evalError) {
                        if (cp->attrs[i]->namespace) {
                            Tcl_AppendResult (interp, " ",
                                              cp->attrs[i]->namespace, ":",
                                              cp->attrs[i]->name, NULL);
                        } else {
                            Tcl_AppendResult (interp, " ", cp->attrs[i]->name,
                                              NULL);
                        }
                    }
                }
            }
        }
        if (!sdata->reportCmd) {
            sdata->validationState = VALIDATION_ERROR;
            return TCL_ERROR;
................................................................................
            }
            
            switch (cp->content[ac]->type) {
            case SCHEMA_CTYPE_KEYSPACE_END:
                cp->content[ac]->keySpace->active--;
                if (!cp->content[ac]->keySpace->active) {
                    if (cp->content[ac]->keySpace->unknownIDrefs) {
                        if (!recover (interp, sdata, S("INVALID_KEYREF"), 0, 0)) {
                            return 0;
                        }
                        cp->content[ac]->keySpace->unknownIDrefs = 0;
                    }
                    Tcl_DeleteHashTable (&cp->content[ac]->keySpace->ids);
                }
                break;
................................................................................
{
    Tcl_HashEntry *h, *h1;
    Tcl_HashSearch search, search1;
    int haveErrMsg = 0;
    SchemaDocKey *dk;

    /* TODO: add recovering */
    if (sdata->evalError) return 0;
    if (sdata->unknownIDrefs) {
        if (!recover (interp, sdata, S("UNKOWN_ID"), 0, 0)) {
            haveErrMsg = 1;
            SetResult ("References to unknown IDs:");
            for (h = Tcl_FirstHashEntry (&sdata->ids, &search);
                 h != NULL;
                 h = Tcl_NextHashEntry (&search)) {
                if (Tcl_GetHashValue (h) == 0) {
                    Tcl_AppendResult (interp, " '",
                                      Tcl_GetHashKey (&sdata->ids, h),
                                      "'", NULL);
                }
            }
        }
    }
    if (sdata->idTables.numEntries) {
        for (h = Tcl_FirstHashEntry (&sdata->idTables, &search);
             h != NULL;
             h = Tcl_NextHashEntry (&search)) {
            dk = Tcl_GetHashValue (h);
            if (dk->unknownIDrefs) {
                if (!recover (interp, sdata, S("UNKOWN_GLOBAL_ID"), 0, 0)) {
                    if (haveErrMsg) {
                        Tcl_AppendResult (interp, "\n", NULL);
                    } else {
                        haveErrMsg = 1;
                    }
                    Tcl_AppendResult (interp,
                                      "References to unknown IDs in ID space '",
                                      Tcl_GetHashKey (&sdata->idTables, h),
                                      "':", NULL);
                    for (h1 = Tcl_FirstHashEntry (&dk->ids, &search1);
                         h1 != NULL;
                         h1 = Tcl_NextHashEntry (&search1)) {
                        if (Tcl_GetHashValue (h1) == 0) {
                            Tcl_AppendResult (interp, " '",
                                              Tcl_GetHashKey (&dk->ids, h1),
                                              "'", NULL);
                        }
                    }
                }
            }
        }
    }
    if (haveErrMsg) {
        sdata->validationState = VALIDATION_ERROR;
................................................................................
        popStack (sdata);
        if (sdata->stack == NULL) {
            /* End of the first pattern (the tree root) without error. */
            /* Check for unknown ID references */
            if (!checkDocKeys (interp, sdata)) {
                return TCL_ERROR;
            }
            /*  We have successfully finished validation */
            sdata->validationState = VALIDATION_FINISHED;
        }
        DBG(
            fprintf(stderr, "probeElementEnd: _CAN_ end here.\n");
            serializeStack (sdata);
            );
        return TCL_OK;
    }
    SetResultV ("Missing mandatory content");
    sdata->validationState = VALIDATION_ERROR;
    DBG(
        fprintf(stderr, "probeElementEnd: CAN'T end here.\n");
        serializeStack (sdata);
        );
    return TCL_ERROR;
}
................................................................................
                candidate = cp->content[ac];
                switch (candidate->type) {
                case SCHEMA_CTYPE_TEXT:
                    if (checkText (interp, candidate, text)) {
                        updateStack (se, cp, ac);
                        return 1;
                    }
                    if (sdata->evalError) return 0;
                    if (recover (interp, sdata, S("INVALID_VALUE"), 0, 0)) {

                        updateStack (se, cp, ac);
                        return 1;
                    } else {
                        return 0;
                    }
                    SetResult ("Invalid text content");
                    return 0;

                case SCHEMA_CTYPE_CHOICE:
                    if (candidate->flags & MIXED_CONTENT) {
                        updateStack (se, cp, ac);
                        return 1;
                    }
................................................................................
                                updateStack (se, cp, ac);
                                return 1;
                            }
                            popStack (sdata);
                            break;

                        case SCHEMA_CTYPE_VIRTUAL:
                            Tcl_Panic ("Virtual constrain in MIXED or"
                                       " CHOICE");
                            
                        case SCHEMA_CTYPE_CHOICE:
                            Tcl_Panic ("MIXED or CHOICE child of MIXED or"
                                       " CHOICE");

                        case SCHEMA_CTYPE_KEYSPACE_END:
                        case SCHEMA_CTYPE_KEYSPACE:
                            Tcl_Panic ("Keyspace constrain in MIXED or"
                                       " CHOICE");
                            
                        }
                    }
                    if (mustMatch (cp->quants[ac], hm)) {
                        if (recover (interp, sdata, S("MISSING_ONE_OF_CHOICE"),
                                                      0, 0)) {
                            break;
                        }
                        SetResultV ("Unexpected text content");
                        return 0;
                    }
                    break;

                case SCHEMA_CTYPE_INTERLEAVE:
                case SCHEMA_CTYPE_PATTERN:
                    pushToStack (sdata, candidate, ac);
                    if (matchText (interp, sdata, text)) {
                        updateStack (se, cp, ac);
                        return 1;
                    }
                    popStack (sdata);
                    if (mustMatch (cp->quants[ac], hm)) {
                        if (recover (interp, sdata, S("MISSING_CP"),
                                                      0, 0)) {
                            break;
                        }
                        SetResultV ("Unexpected text content");
                        return 0;
                    }
                    break;

                case SCHEMA_CTYPE_VIRTUAL:
                    if (!evalVirtual (interp, sdata, ac)) return 0;
                    break;
................................................................................
                    }
                    break;
                    
                case SCHEMA_CTYPE_KEYSPACE_END:
                    cp->content[ac]->keySpace->active--;
                    if (!cp->content[ac]->keySpace->active) {
                        if (cp->content[ac]->keySpace->unknownIDrefs) {
                            if (!recover (interp, sdata, S("INVALID_KEYREF"),
                                          0, 0)) {
                                return 0;
                            }
                            cp->content[ac]->keySpace->unknownIDrefs = 0;
                        }
                        Tcl_DeleteHashTable (&cp->content[ac]->keySpace->ids);
                    }
                    break;
                    
                case SCHEMA_CTYPE_NAME:
                case SCHEMA_CTYPE_ANY:
                    if (mustMatch (cp->quants[ac], hm)) {
                        if (recover (interp, sdata, S("MISSING_ELEMENT"),
                                                      0, 0)) {
                            break;
                        }
                        SetResultV ("Unexpected text content");
                        return 0;
                    }
                    break;

                }
                ac++;
            }
            if (isName) {
                if (recover (interp, sdata, S("MISSING_ELEMENT"), 0, 0)) {
                    return 1;
                }
                SetResultV ("Unexpected text content");
                return 0;
            }
            popStack (sdata);
            continue;

        case SCHEMA_CTYPE_KEYSPACE:
        case SCHEMA_CTYPE_KEYSPACE_END:
................................................................................
            break;
        }
        if (only_whites)  return TCL_OK;
        if (matchText (interp, sdata, text)) {
            return TCL_OK;
        }
    }



    if (!sdata->evalError) {
        SetResult ("Text content doesn't match");
    }
    return TCL_ERROR;
}

static void

Changes to generic/schema.h.

112
113
114
115
116
117
118

119
120
121
122
123
124
125
} SchemaCP;

typedef struct SchemaValidationStack
{
    SchemaCP *pattern;
    struct SchemaValidationStack *next;
    struct SchemaValidationStack *down;

    int               activeChild;
    int               hasMatched;
    int              *interleaveState;
} SchemaValidationStack;

typedef enum {
    VALIDATION_READY,







>







112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
} SchemaCP;

typedef struct SchemaValidationStack
{
    SchemaCP *pattern;
    struct SchemaValidationStack *next;
    struct SchemaValidationStack *down;
    int               startChild;
    int               activeChild;
    int               hasMatched;
    int              *interleaveState;
} SchemaValidationStack;

typedef enum {
    VALIDATION_READY,

Changes to tests/schema.test.

5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
....
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
....
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
....
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
....
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
        {<doc><items><item ref="1"/><item ref="1"/></items><items><item ref="1"/><item ref="1"/></items></doc>}
        {<doc><items><item ref="1"/><item ref="a"/></items><items><item ref="b"/><item ref="1"/></items></doc>}
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {1 s WRONG_ATTRIBUTE_VALUE s WRONG_ATTRIBUTE_VALUE 1}

test schema-18.5 {reportcmd} {
    tdom::schema s
    s define {
        defelement doc {
            element items * {
                element item * {
................................................................................
        {<doc><items><item>>12</item><item>ab</item></items></doc>}

    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {s WRONG_VALUE 1 s WRONG_VALUE s MISSING_TEXT 1 1}

test schema-18.6 {reportcmd} {
    tdom::schema s
    s define {
        defelement item {
            text {
                key lang
................................................................................
        {<doc><items><item>12</item><item>12</item></items><items><item>ab</item><item>cd</item></items></doc>}
        {<doc><items><item>12</item><item>12</item></items><items><item>ab</item><item>cd</item></items><items><item>12</item><item>12</item></items></doc>}
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {1 s WRONG_VALUE 1 s WRONG_VALUE 1 s WRONG_VALUE s WRONG_VALUE 1}

proc schema-18.7 {args} {
    global result
    lappend result "tclcallback"
}

test schema-18.7 {reportcmd} {
................................................................................
        {<doc><items><item ref="1"/><item ref="1"/></items><items><item ref="1"/><item ref="1"/></items></doc>}
        {<doc><items><item ref="1"/><item ref="a"/></items><items><item ref="c"/><item ref="d"/></items></doc>}
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {s WRONG_ATTRIBUTE_VALUE s WRONG_ATTRIBUTE_VALUE 1 1}

test schema-19.3 {keyspace} {
    tdom::schema s
    s define {
        defelement doc {
            element items *
        }
................................................................................
        {<doc><items><item ref="a" id="1"/></items></doc>}
        {<doc><items><item ref="1"/><item id="1"/></items><items><item ref="1"/><item ref="1"/></items></doc>}
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {1 1 s UNKNOWN_KEYREF 1 s UNKNOWN_KEYREF 1}

test schema-20.1 {domunique} {
    set schema {
        prefixns {ns1 http://tdom.org/test}
        defelement doc {
            domunique ${::schema-20.1} @ref
        }







|







 







|







 







|







 







|







 







|







5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
....
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
....
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
....
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
....
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
        {<doc><items><item ref="1"/><item ref="1"/></items><items><item ref="1"/><item ref="1"/></items></doc>}
        {<doc><items><item ref="1"/><item ref="a"/></items><items><item ref="b"/><item ref="1"/></items></doc>}
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {1 s INVALID_ATTRIBUTE_VALUE s INVALID_ATTRIBUTE_VALUE 1}

test schema-18.5 {reportcmd} {
    tdom::schema s
    s define {
        defelement doc {
            element items * {
                element item * {
................................................................................
        {<doc><items><item>>12</item><item>ab</item></items></doc>}

    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {s INVALID_VALUE 1 s INVALID_VALUE s MISSING_TEXT 1 1}

test schema-18.6 {reportcmd} {
    tdom::schema s
    s define {
        defelement item {
            text {
                key lang
................................................................................
        {<doc><items><item>12</item><item>12</item></items><items><item>ab</item><item>cd</item></items></doc>}
        {<doc><items><item>12</item><item>12</item></items><items><item>ab</item><item>cd</item></items><items><item>12</item><item>12</item></items></doc>}
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {1 s INVALID_VALUE 1 s INVALID_VALUE 1 s INVALID_VALUE s INVALID_VALUE 1}

proc schema-18.7 {args} {
    global result
    lappend result "tclcallback"
}

test schema-18.7 {reportcmd} {
................................................................................
        {<doc><items><item ref="1"/><item ref="1"/></items><items><item ref="1"/><item ref="1"/></items></doc>}
        {<doc><items><item ref="1"/><item ref="a"/></items><items><item ref="c"/><item ref="d"/></items></doc>}
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {s INVALID_ATTRIBUTE_VALUE s INVALID_ATTRIBUTE_VALUE 1 1}

test schema-19.3 {keyspace} {
    tdom::schema s
    s define {
        defelement doc {
            element items *
        }
................................................................................
        {<doc><items><item ref="a" id="1"/></items></doc>}
        {<doc><items><item ref="1"/><item id="1"/></items><items><item ref="1"/><item ref="1"/></items></doc>}
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {1 1 s INVALID_KEYREF 1 s INVALID_KEYREF 1}

test schema-20.1 {domunique} {
    set schema {
        prefixns {ns1 http://tdom.org/test}
        defelement doc {
            domunique ${::schema-20.1} @ref
        }