tDOM

Changes On Branch domvalidation
Login

Changes On Branch domvalidation

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

Changes In Branch domvalidation Excluding Merge-Ins

This is equivalent to a diff from 57cf341505 to c4947454bc

2020-07-23
00:03
Cherry-pick by hand of [c4947454bce0]. check-in: ba1e7f4ba5 user: rolf tags: trunk
2020-07-22
00:49
Added "tabs" as possible value to asXML -indent and do the indentation with tabs, if given. check-in: cf00a7c899 user: rolf tags: tabs
2020-07-11
01:04
Fixed bug in case of unknown empty document element. Leaf check-in: c4947454bc user: rolf tags: domvalidation
2020-07-10
18:15
Made dom parse -dtdvalidation a (by default enabled) build option. check-in: 2c055a1883 user: rolf tags: domvalidation
00:31
Merged from trunk. check-in: 174626facf user: rolf tags: domvalidation
00:08
Minor documentation work. check-in: 57cf341505 user: rolf tags: trunk
2020-07-03
11:12
User configurable separator character between namespace URI and local name for XML namespace-aware SAX parser: Added the option -namespaceseparator to the expat command. check-in: 515c90d025 user: rolf tags: trunk

Changes to configure.

757
758
759
760
761
762
763

764
765
766
767
768
769
770
with_celib
enable_symbols
enable_dtd
enable_ns
enable_ucmd
enable_tdomalloc
enable_lessns

'
      ac_precious_vars='build_alias
host_alias
target_alias
CC
CFLAGS
LDFLAGS







>







757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
with_celib
enable_symbols
enable_dtd
enable_ns
enable_ucmd
enable_tdomalloc
enable_lessns
enable_dtdvalidation
'
      ac_precious_vars='build_alias
host_alias
target_alias
CC
CFLAGS
LDFLAGS
1403
1404
1405
1406
1407
1408
1409

1410
1411
1412
1413
1414
1415
1416
  --enable-symbols        build with debugging symbols (default: off)
  --enable-dtd            build with dtd support (default: on)
  --enable-ns             build with XML namespace support (default: on)
  --enable-unknown        enable built-in unknown command (default: off)
  --enable-tdomalloc      build with the tDOM allocator (default: off)
  --enable-lessns         build with lower limit for XML ns declarations
                          (default: off)


Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-tcl              directory containing tcl configuration
                          (tclConfig.sh)
  --with-aolserver        directory with AOLserver distribution







>







1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
  --enable-symbols        build with debugging symbols (default: off)
  --enable-dtd            build with dtd support (default: on)
  --enable-ns             build with XML namespace support (default: on)
  --enable-unknown        enable built-in unknown command (default: off)
  --enable-tdomalloc      build with the tDOM allocator (default: off)
  --enable-lessns         build with lower limit for XML ns declarations
                          (default: off)
  --enable-dtdvalidation  build with valiation features (default: on)

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-tcl              directory containing tcl configuration
                          (tclConfig.sh)
  --with-aolserver        directory with AOLserver distribution
8889
8890
8891
8892
8893
8894
8895




























8896
8897
8898
8899
8900
8901
8902
        $as_echo "#define TDOM_LESS_NS 1" >>confdefs.h

    else
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
    fi






























TDOMSHELL=tcldomsh



    #--------------------------------------------------------------------
    # These are for ${PACKAGE_NAME}Config.sh







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







8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
        $as_echo "#define TDOM_LESS_NS 1" >>confdefs.h

    else
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
    fi


    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable dtd valiation" >&5
$as_echo_n "checking whether to enable dtd valiation... " >&6; }
    # Check whether --enable-dtdvalidation was given.
if test "${enable_dtdvalidation+set}" = set; then :
  enableval=$enable_dtdvalidation; tcl_ok=$enableval
else
  tcl_ok=yes
fi


    if test "${enable_dtdvalidation+set}" = set; then
        enableval="$enable_dtdvalidation"
        tcl_ok=$enableval
    else
        tcl_ok=yes
    fi

    if test "$tcl_ok" = "no" ; then
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
        $as_echo "#define TDOM_NO_DTD_VALIDATION 1" >>confdefs.h

    else
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
    fi


TDOMSHELL=tcldomsh



    #--------------------------------------------------------------------
    # These are for ${PACKAGE_NAME}Config.sh

Changes to configure.ac.

215
216
217
218
219
220
221

222
223
224
225
226
227
228
#--------------------------------------------------------------------

TDOM_ENABLE_DTD
TDOM_ENABLE_NS
TDOM_ENABLE_UNKNOWN
TDOM_ENABLE_TDOMALLOC
TDOM_ENABLE_LESS_NS


TDOMSHELL=tcldomsh
AC_SUBST(TDOMSHELL)

TDOM_EXPORT_CONFIG

#--------------------------------------------------------------------







>







215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#--------------------------------------------------------------------

TDOM_ENABLE_DTD
TDOM_ENABLE_NS
TDOM_ENABLE_UNKNOWN
TDOM_ENABLE_TDOMALLOC
TDOM_ENABLE_LESS_NS
TDOM_ENABLE_DTD_VALIDATION

TDOMSHELL=tcldomsh
AC_SUBST(TDOMSHELL)

TDOM_EXPORT_CONFIG

#--------------------------------------------------------------------

Changes to doc/domNode.xml.

376
377
378
379
380
381
382
383
384
385

386
387
388
389
390
391
392
another data type, if needed.</p>

<p>Similar to the way described above to inject literals in a secure
way into the XPath expression using tcl variable references there is a
syntax to inject element names from tcl variables. At every place
where the XPath syntax allows a node test there could be a tcl
variable reference (in any form), just the leading $ replaced with %.
This allows one to select nodes with 'strange' (invalid, according to the
appropriate XML production rule) node names which may be needed in
case of working with JSON data.</p>


<p>The option <m>-namespaces</m> expects a tcl list with prefix /
namespace pairs as argument. If this option is not given, then any
namespace prefix within the xpath expression will be first resolved
against the list of prefix / namespace pairs set with the
selectNodesNamespaces method for the document, the node belongs to. If
this fails, then the namespace definitions in scope of the context







|
|
|
>







376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
another data type, if needed.</p>

<p>Similar to the way described above to inject literals in a secure
way into the XPath expression using tcl variable references there is a
syntax to inject element names from tcl variables. At every place
where the XPath syntax allows a node test there could be a tcl
variable reference (in any form), just the leading $ replaced with %.
This allows one to select nodes with 'strange' (invalid, according to
the appropriate XML production rule) node names which may be needed in
case of working with JSON data or if the DOM tree was build with
<m>-ignorexmlns</m>.</p>

<p>The option <m>-namespaces</m> expects a tcl list with prefix /
namespace pairs as argument. If this option is not given, then any
namespace prefix within the xpath expression will be first resolved
against the list of prefix / namespace pairs set with the
selectNodesNamespaces method for the document, the node belongs to. If
this fails, then the namespace definitions in scope of the context

Changes to extensions/tnc/tnc.c.

2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
                 "shouldn't be reached in any case.\n");
    default:
        fprintf (stderr, "error!!! - in TncProbeElementEnd: unknown content "
                 "type: %d\n", stackelm.model->type);
        return 1;
    }
}


/*
 *----------------------------------------------------------------------------
 *
 * TncElementEndCommand --
 *
 *	This procedure is called for every element end event







<







2059
2060
2061
2062
2063
2064
2065

2066
2067
2068
2069
2070
2071
2072
                 "shouldn't be reached in any case.\n");
    default:
        fprintf (stderr, "error!!! - in TncProbeElementEnd: unknown content "
                 "type: %d\n", stackelm.model->type);
        return 1;
    }
}


/*
 *----------------------------------------------------------------------------
 *
 * TncElementEndCommand --
 *
 *	This procedure is called for every element end event

Changes to generic/dom.c.

118
119
120
121
122
123
124













































































































































125
126
127
128
129
130
131
typedef struct _domActiveBaseURI {

    int   depth;
    const char *baseURI;

} domActiveBaseURI;














































































































































/*---------------------------------------------------------------------------
|   type domReadInfo
|
\--------------------------------------------------------------------------*/
typedef struct _domReadInfo {

    XML_Parser        parser;







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







118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
typedef struct _domActiveBaseURI {

    int   depth;
    const char *baseURI;

} domActiveBaseURI;


#ifndef TDOM_NO_DTD_VALIDATION
/* The elements of TNC_Content carry exactly the same information
   as expats XML_Content. But the element is identified by his
   Tcl_HashEntry entry within the "tagNames" Hashtable (see TNC_Data)
   and not the element name. This should be much more efficient. */
typedef struct TNC_cp TNC_Content;
typedef struct TNC_elemAttInfo TNC_ElemAttInfo;

struct TNC_cp
{
    enum XML_Content_Type   type;
    enum XML_Content_Quant  quant;
    Tcl_HashEntry          *nameId;
    unsigned int            numchildren;
    TNC_Content            *children;
    TNC_ElemAttInfo        *attInfo;
};

typedef struct TNC_contentStack
{
    TNC_Content  *model;
    int           activeChild;
    int           deep;
    int           alreadymatched;
} TNC_ContentStack;

typedef enum TNC_attType {
    TNC_ATTTYPE_CDATA,
    TNC_ATTTYPE_ID,
    TNC_ATTTYPE_IDREF,
    TNC_ATTTYPE_IDREFS,
    TNC_ATTTYPE_ENTITY,
    TNC_ATTTYPE_ENTITIES,
    TNC_ATTTYPE_NMTOKEN,
    TNC_ATTTYPE_NMTOKENS,
    TNC_ATTTYPE_NOTATION,
    TNC_ATTTYPE_ENUMERATION,
} TNC_AttType;

struct TNC_elemAttInfo
{
    Tcl_HashTable *attributes;
    int            nrOfreq;
    int            nrOfIdAtts;
};

typedef struct TNC_attDecl
{
    TNC_AttType    att_type;
    char          *dflt;
    int            isrequired;
    Tcl_HashTable *lookupTable;   /* either NotationTypes or enum values */
} TNC_AttDecl;

typedef struct TNC_entityInfo
{
    int    is_notation;
    char  *notationName;
} TNC_EntityInfo;

typedef Tcl_HashEntry TNC_NameId;

#define TNC_INITCONTENTSTACKSIZE 512

enum TNC_Error {
    TNC_ERROR_NONE,
    TNC_ERROR_DUPLICATE_ELEMENT_DECL,
    TNC_ERROR_DUPLICATE_MIXED_ELEMENT,
    TNC_ERROR_UNKNOWN_ELEMENT,
    TNC_ERROR_EMPTY_ELEMENT,
    TNC_ERROR_DISALLOWED_PCDATA,
    TNC_ERROR_DISALLOWED_CDATA,
    TNC_ERROR_NO_DOCTYPE_DECL,
    TNC_ERROR_WRONG_ROOT_ELEMENT,
    TNC_ERROR_NO_ATTRIBUTES,
    TNC_ERROR_UNKNOWN_ATTRIBUTE,
    TNC_ERROR_WRONG_FIXED_ATTVALUE,
    TNC_ERROR_MISSING_REQUIRED_ATTRIBUTE,
    TNC_ERROR_MORE_THAN_ONE_ID_ATT,
    TNC_ERROR_ID_ATT_DEFAULT,
    TNC_ERROR_DUPLICATE_ID_VALUE,
    TNC_ERROR_UNKNOWN_ID_REFERRED,
    TNC_ERROR_ENTITY_ATTRIBUTE,
    TNC_ERROR_ENTITIES_ATTRIBUTE,
    TNC_ERROR_ATT_ENTITY_DEFAULT_MUST_BE_DECLARED,
    TNC_ERROR_NOTATION_REQUIRED,
    TNC_ERROR_NOTATION_MUST_BE_DECLARED,
    TNC_ERROR_IMPOSSIBLE_DEFAULT,
    TNC_ERROR_ENUM_ATT_WRONG_VALUE,
    TNC_ERROR_NMTOKEN_REQUIRED,
    TNC_ERROR_NAME_REQUIRED,
    TNC_ERROR_NAMES_REQUIRED,
    TNC_ERROR_ELEMENT_NOT_ALLOWED_HERE,
    TNC_ERROR_ELEMENT_CAN_NOT_END_HERE,
    TNC_ERROR_ONLY_THREE_BYTE_UTF8,
    TNC_ERROR_UNKNOWN_NODE_TYPE
};

const char *
TNC_ErrorString (int code)
{
    static const char *message[] = {
        "No error.",
        "Element declared more than once.",
        "The same name must not appear more than once in \n\tone mixed-content declaration.",
        "No declaration for this element.",
        "Element is declared to be empty, but isn't.",
        "PCDATA not allowed here.",
        "CDATA section not allowed here.",
        "No DOCTYPE declaration.",
        "Root element doesn't match DOCTYPE name.",
        "No attributes defined for this element.",
        "Unknown attribute for this element.",
        "Attribute value must match the FIXED default.",
        "Required attribute missing.",
        "Only one attribute with type ID allowed.",
        "No default value allowed for attribute type ID.",
        "ID attribute values must be unique within the document.",
        "Unknown ID referred.",
        "Attribute value has to be a unparsed entity.",
        "Attribute value has to be a sequence of unparsed entities.",
        "The defaults of attributes with type ENTITY or ENTITIES\nhas to be unparsed entities.",
        "Attribute value has to be one of the allowed notations.",
        "Every used NOTATION must be declared.",
        "Attribute default is not one of the allowed values",
        "Attribute hasn't one of the allowed values.",
        "Attribute value has to be a NMTOKEN.",
        "Attribute value has to be a Name.",
        "Attribute value has to match production Names.",
        "Element is not allowed here.",
        "Element can not end here (required element(s) missing).",
        "Can only handle UTF8 chars up to 3 bytes length."
        "Unknown or unexpected dom node type."
    };
/*      if (code > 0 && code < sizeof(message)/sizeof(message[0])) */
        return message[code];
    return 0;
}
#endif

/*---------------------------------------------------------------------------
|   type domReadInfo
|
\--------------------------------------------------------------------------*/
typedef struct _domReadInfo {

    XML_Parser        parser;
144
145
146
147
148
149
150



151
152














































153
154
155
156
157
158
159
160

















161
162
163
164
165
166
167
    int               activeNSsize;
    int               activeNSpos;
    domActiveNS      *activeNS;
    int               baseURIstackSize;
    int               baseURIstackPos;
    domActiveBaseURI *baseURIstack;
    int               insideDTD;



    int               status;















































} domReadInfo;

/*----------------------------------------------------------------------------
|   Prototypes
|
\---------------------------------------------------------------------------*/
static void DispatchPCDATA (domReadInfo *info);



















#ifndef TCL_THREADS

/*---------------------------------------------------------------------------
|   domModuleFinalize
|
\--------------------------------------------------------------------------*/







>
>
>

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








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







285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
    int               activeNSsize;
    int               activeNSpos;
    domActiveNS      *activeNS;
    int               baseURIstackSize;
    int               baseURIstackPos;
    domActiveBaseURI *baseURIstack;
    int               insideDTD;
#ifndef TDOM_NO_DTD_VALIDATION
    int               dtdvalidation;
#endif
    int               status;
#ifndef TDOM_NO_DTD_VALIDATION
    /* DTD validation releated struct members follow */
    char             *doctypeName;            /* From DOCTYPE declaration */
    int               skipWhiteCDATAs;        /* Flag: white space allowed in 
                                                 current content model? */
    int               ignorePCDATA;           /* Flag: currently mixed content
                                                 model? */
    Tcl_HashTable    *tagNames;               /* Hash table of all ELEMENT
                                                 declarations of the DTD.
                                                 Element name is the key.
                                                 While parsing, entry points
                                                 to the XML_Content of that
                                                 Element, after finishing of
                                                 DTD parsing, entry holds a
                                                 pointer to the TNC_Content
                                                 of that element. */
    TNC_ElemAttInfo  *elemAttInfo;            /* TncElementStartCommand stores
                                                 the elemAttInfo pointer of
                                                 the current element here for
                                                 DOM validation, to avoid two
                                                 element name lookups. */
    int               elemContentsRewriten;   /* Signals, if the tagNames
                                                 entries point to
                                                 TNC_Contents */
    int               dtdstatus;              /* While used with expat obj:
                                                 1 after successful parsed
                                                 DTD, 0 otherwise.
                                                 For validateCmd used for
                                                 error report during
                                                 validation: 0 OK, 1 validation
                                                 error. */
    int               idCheck;                /* Flag: check IDREF resolution*/
    Tcl_HashTable    *attDefsTables;          /* Used to store ATTLIST 
                                                 declarations while parsing.
                                                 Keys are the element names. */
    Tcl_HashTable    *entityDecls;            /* Used to store ENTITY
                                                 declarations. */
    Tcl_HashTable    *notationDecls;          /* Used to store NOTATION
                                                 declarations. */
    Tcl_HashTable    *ids;                    /* Used to track IDs */
    int               contentStackSize;       /* Current size of the content
                                                 stack */
    int               contentStackPtr;        /* Points to the currently active
                                                 content model on the stack */
    TNC_ContentStack *contentStack;           /* Stack for the currently
                                                 nested open content models. */
#endif
} domReadInfo;

/*----------------------------------------------------------------------------
|   Prototypes
|
\---------------------------------------------------------------------------*/
static void DispatchPCDATA (domReadInfo *info);

#ifndef TDOM_NO_DTD_VALIDATION
#define CHECK_UTF_CHARLEN(d) if (!(d)) { \
                                signalNotValid (userData, TNC_ERROR_ONLY_THREE_BYTE_UTF8);\
                                return;\
                             }

#define CHECK_UTF_CHARLENR(d) if (!(d)) { \
                                signalNotValid (userData, TNC_ERROR_ONLY_THREE_BYTE_UTF8);\
                                return 0;\
                             }

#define CHECK_UTF_CHARLEN_COPY(d) if (!(d)) { \
                                signalNotValid (userData, TNC_ERROR_ONLY_THREE_BYTE_UTF8);\
                                FREE (copy);\
                                return;\
                                }
#endif

#ifndef TCL_THREADS

/*---------------------------------------------------------------------------
|   domModuleFinalize
|
\--------------------------------------------------------------------------*/
227
228
229
230
231
232
233






















234
235
236
237
238
239
240
    return (domTextNode *)n;
}

domProcessingInstructionNode * coerceToProcessingInstructionNode( domNode *n ) {
    return (domProcessingInstructionNode *)n;
}























/*---------------------------------------------------------------------------
|   domIsNAME
|
\--------------------------------------------------------------------------*/
int
domIsNAME (
    const char *name







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







434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
    return (domTextNode *)n;
}

domProcessingInstructionNode * coerceToProcessingInstructionNode( domNode *n ) {
    return (domProcessingInstructionNode *)n;
}


#ifndef TDOM_NO_DTD_VALIDATION
static void
signalNotValid (userData, code)
    void        *userData;
    int          code;
{
    domReadInfo *tncdata = (domReadInfo *) userData;
    char linenr[50], colnr[50];
    
    
    tncdata->status = TCL_ERROR;
    sprintf(linenr, "%ld", XML_GetCurrentLineNumber(tncdata->parser));
    sprintf(colnr, "%ld", XML_GetCurrentColumnNumber(tncdata->parser));
    Tcl_ResetResult (tncdata->interp);
    Tcl_AppendResult (tncdata->interp, "At line ", linenr, ", column ",
                      colnr, ": ", (char *)TNC_ErrorString (code),
                      NULL);
    XML_StopParser(tncdata->parser, 1);
}
#endif

/*---------------------------------------------------------------------------
|   domIsNAME
|
\--------------------------------------------------------------------------*/
int
domIsNAME (
    const char *name
1111
1112
1113
1114
1115
1116
1117





























































































































































































































































































































































































































































































































































































































































































































































































































































































































































1118
1119
1120
1121
1122
1123
1124
    }
    /* Not reached */
    return NULL;
}

#ifndef  TDOM_NO_EXPAT































































































































































































































































































































































































































































































































































































































































































































































































































































































































































/*---------------------------------------------------------------------------
|   startElement
|
\--------------------------------------------------------------------------*/
static void
startElement(







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







1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
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
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
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
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
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
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
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
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
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
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
2048
2049
2050
2051
2052
2053
2054
2055
2056
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
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
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
2199
2200
2201
2202
2203
2204
2205
2206
2207
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
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
    }
    /* Not reached */
    return NULL;
}

#ifndef  TDOM_NO_EXPAT

#ifndef TDOM_NO_DTD_VALIDATION
/*
 *----------------------------------------------------------------------------
 *
 * TncRewriteModel --
 *
 *	This helper procedure creates recursively a TNC_Content from
 *      a XML_Content.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Allocates memory for the TNC_Content models.
 *
 *----------------------------------------------------------------------------
 */

static void
TncRewriteModel (
    XML_Content   *emodel,
    TNC_Content   *tmodel,
    Tcl_HashTable *tagNames
)
{
    Tcl_HashEntry *entryPtr;
    unsigned int i;

    tmodel->type = emodel->type;
    tmodel->quant = emodel->quant;
    tmodel->numchildren = emodel->numchildren;
    tmodel->children = NULL;
    tmodel->nameId = NULL;
    switch (emodel->type) {
    case XML_CTYPE_MIXED:
        if (emodel->quant == XML_CQUANT_REP) {
            tmodel->children = (TNC_Content *)
                MALLOC (sizeof (TNC_Content) * emodel->numchildren);
            for (i = 0; i < emodel->numchildren; i++) {
                TncRewriteModel (&emodel->children[i], &tmodel->children[i],
                                 tagNames);
            }
        }
        break;
    case XML_CTYPE_ANY:
    case XML_CTYPE_EMPTY:
        /* do nothing */
        break;
    case XML_CTYPE_SEQ:
    case XML_CTYPE_CHOICE:
        tmodel->children = (TNC_Content *)
            MALLOC (sizeof (TNC_Content) * emodel->numchildren);
        for (i = 0; i < emodel->numchildren; i++) {
            TncRewriteModel (&emodel->children[i], &tmodel->children[i],
                             tagNames);
        }
        break;
    case XML_CTYPE_NAME:
        entryPtr = Tcl_FindHashEntry (tagNames, emodel->name);
        /* Notice, that it is possible for entryPtr to be NULL.
           This means, a content model uses a not declared element.
           This is legal even in valid documents. (Of course, if the
           undeclared element actually shows up in the document
           that would make the document invalid.) See rec 3.2

           QUESTION: Should there be a flag to enable a warning,
           when a declaration contains an element type for which
           no declaration is provided, as rec 3.2 metioned?
           This would be the appropriated place to omit the
           warning. */
        tmodel->nameId = entryPtr;
    }
}

/*
 *----------------------------------------------------------------------------
 *
 * TncEndDoctypeDeclHandler --
 *
 *	This procedure is called at the end of the DOCTYPE
 *      declaration, after processing any external subset.
 *      It rewrites the XML_Content models to TNC_Content
 *      models and frees the XML_Content models.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Rewrites the XML_Content models to TNC_Content
 *      models.
 *
 *----------------------------------------------------------------------------
 */

static void
TncEndDoctypeDeclHandler (
    void *userData
)
{
    domReadInfo *tncdata = (domReadInfo *) userData;
    Tcl_HashEntry *entryPtr, *ePtr1;
    Tcl_HashSearch search;
    XML_Content   *emodel;
    TNC_Content   *tmodel = NULL;
    char *elementName;

    entryPtr = Tcl_FirstHashEntry (tncdata->tagNames, &search);
    while (entryPtr != NULL) {
#ifdef TNC_DEBUG
        printf ("name: %-20s   nameId: %p\n",
                Tcl_GetHashKey (tncdata->tagNames, entryPtr),
                entryPtr);
#endif
        emodel = (XML_Content*) Tcl_GetHashValue (entryPtr);
        tmodel = (TNC_Content*) MALLOC (sizeof (TNC_Content));
        TncRewriteModel (emodel, tmodel, tncdata->tagNames);
        elementName = Tcl_GetHashKey (tncdata->tagNames, entryPtr);
        ePtr1 = Tcl_FindHashEntry (tncdata->attDefsTables, elementName);
        if (ePtr1) {
            tmodel->attInfo = (TNC_ElemAttInfo *) Tcl_GetHashValue (ePtr1);
        } else {
            tmodel->attInfo = NULL;
        }
        Tcl_SetHashValue (entryPtr, tmodel);
        XML_MemFree (tncdata->parser, emodel);
        entryPtr = Tcl_NextHashEntry (&search);
    }
    tncdata->elemContentsRewriten = 1;
    /* Checks, if every used notation name is in deed declared */
    entryPtr = Tcl_FirstHashEntry (tncdata->notationDecls, &search);
    while (entryPtr != NULL) {
#ifdef TNC_DEBUG
        printf ("check notation name %s\n",
                Tcl_GetHashKey (tncdata->notationDecls, entryPtr));
        printf ("value %p\n", Tcl_GetHashValue (entryPtr));
#endif
        if (!Tcl_GetHashValue (entryPtr)) {
            signalNotValid (userData, TNC_ERROR_NOTATION_MUST_BE_DECLARED);
            return;
        }
        entryPtr = Tcl_NextHashEntry (&search);
    }
    /* Checks, if every used entity name is indeed declared */
    entryPtr = Tcl_FirstHashEntry (tncdata->entityDecls, &search);
    while (entryPtr != NULL) {
        if (!Tcl_GetHashValue (entryPtr)) {
            signalNotValid (userData,
                            TNC_ERROR_ATT_ENTITY_DEFAULT_MUST_BE_DECLARED);
            return;
        }
        entryPtr = Tcl_NextHashEntry (&search);
    }
    tncdata->dtdstatus = 1;
}

/*
 *----------------------------------------------------------------------------
 *
 * TncProbeElement --
 *
 *	This function checks, if the element match the
 *      topmost content model on the content stack.
 *
 * Results:
 *	1 if the element match,
 *      0 if not.
 *     -1 if not, but this isn't a validation error
 *
 * Side effects:
 *	Eventually pushes data to the contentStack (even in
 *      recurive calls).
 *
 *----------------------------------------------------------------------------
 */

static int
TncProbeElement (
    TNC_NameId *nameId,
    domReadInfo   *tncdata
)
{
    TNC_ContentStack *stackelm;
    TNC_Content *activeModel;
    int myStackPtr, zeroMatchPossible, result;
    unsigned int i, seqstartindex;

#ifdef TNC_DEBUG
    printf ("TncProbeElement start\n");
    printContentStack (tncdata);
#endif
    myStackPtr = tncdata->contentStackPtr - 1;
    stackelm = &(tncdata->contentStack)[myStackPtr];
    switch (stackelm->model->type) {
    case XML_CTYPE_MIXED:
#ifdef TNC_DEBUG
        printf ("TncProbeElement XML_CTYPE_MIXED\n");
#endif
        for (i = 0; i < stackelm->model->numchildren; i++) {
            if ((&stackelm->model->children[i])->nameId == nameId) {
                return 1;
            }
        }
        return 0;
    case XML_CTYPE_ANY:
#ifdef TNC_DEBUG
        printf ("TncProbeElement XML_CTYPE_ANY\n");
#endif
        return 1;
    case XML_CTYPE_EMPTY:
#ifdef TNC_DEBUG
        printf ("TncProbeElement XML_CTYPE_EMPTY\n");
#endif
        return 0;
    case XML_CTYPE_CHOICE:
#ifdef TNC_DEBUG
        printf ("TncProbeElement XML_CTYPE_CHOICE\n");
#endif
        if (stackelm->alreadymatched) {
            activeModel = &stackelm->model->children[stackelm->activeChild];
            if (activeModel->type == XML_CTYPE_NAME) {
                /* so this stackelement must be the topmost */
                if (activeModel->quant == XML_CQUANT_REP
                    || activeModel->quant == XML_CQUANT_PLUS) {
                    /* the last matched element is multiple, maybe it
                       matches again */
                    if (nameId == activeModel->nameId) {
#ifdef TNC_DEBUG
                        printf ("-->matched! child Nr. %d\n",
                                stackelm->activeChild);
#endif
                        /* stack and activeChild nr. are already OK, just
                           report success. */
                        return 1;
                    }
                }
            }
            /* The active child is a SEQ or CHOICE. */
            if (stackelm->model->quant == XML_CQUANT_NONE ||
                stackelm->model->quant == XML_CQUANT_OPT) {
                /*The child cp's type SEQ or CHOICE keep track by
                  themselve about if they are repeated. Because we are
                  here, they don't.  Since the current cp has already
                  matched and isn't multiple, the current cp as a whole
                  is done.  But no contradiction detected, so return
                  "search further" */
                return -1;
            }
        }

        /* If one of the alternatives within the CHOICE cp is quant
           REP or OPT, it isn't a contradition to the document structure,
           if the cp doesn't match, even if it is quant
           NONE or PLUS, because of the "zero time" match of this one
           alternative. We use zeroMatchPossible, to know about this.*/
        zeroMatchPossible = 0;
        for (i = 0; i < stackelm->model->numchildren; i++) {
            if ((&stackelm->model->children[i])->type == XML_CTYPE_NAME) {
#ifdef TNC_DEBUG
                printf ("child is type NAME\n");
#endif
                if ((&stackelm->model->children[i])->nameId == nameId) {
#ifdef TNC_DEBUG
                    printf ("-->matched! child Nr. %d\n",i);
#endif
                    (&tncdata->contentStack[myStackPtr])->activeChild = i;
                    (&tncdata->contentStack[myStackPtr])->alreadymatched = 1;
                    return 1;
                }
                else {
                    /* If the name child is optional, we have a
                       candidat for "zero match". */
                    if ((&stackelm->model->children[i])->quant
                        == XML_CQUANT_OPT ||
                        (&stackelm->model->children[i])->quant
                        == XML_CQUANT_REP) {
#ifdef TNC_DEBUG
                        printf ("zero match possible\n");
#endif
                        zeroMatchPossible = 1;
                    }
                }
            }
            else {
#ifdef TNC_DEBUG
                printf ("complex child type\n");
#endif
                if (tncdata->contentStackPtr == tncdata->contentStackSize) {
                    tncdata->contentStack = (TNC_ContentStack *)
                        Tcl_Realloc ((char *)tncdata->contentStack,
                                     sizeof (TNC_Content *) * 2 *
                                     tncdata->contentStackSize);
                    tncdata->contentStackSize *= 2;
                }
                (&tncdata->contentStack[tncdata->contentStackPtr])->model
                    = &stackelm->model->children[i];
                tncdata->contentStack[tncdata->contentStackPtr].activeChild
                    = 0;
                tncdata->contentStack[tncdata->contentStackPtr].deep
                    = stackelm->deep + 1;
                tncdata->contentStack[tncdata->contentStackPtr].alreadymatched
                    = 0;
                tncdata->contentStackPtr++;
                result = TncProbeElement (nameId, tncdata);
                if (result == 1) {
#ifdef TNC_DEBUG
                    printf ("-->matched! child nr. %d\n",i);
#endif
                    (&tncdata->contentStack[myStackPtr])->activeChild = i;
                    (&tncdata->contentStack[myStackPtr])->alreadymatched = 1;
                    return 1;
                }
                /* The child cp says, it doesn't has matched, but says
                   also, it's perfectly OK, if it doesn't at all. So we
                   have a candidat for "zero match". */
                if (result == -1) {
                    zeroMatchPossible = 1;
                }
                tncdata->contentStackPtr--;
            }
        }
        /* OK, nobody has claimed a match. Question is: try further or is
           this a document structure error. */
        if (zeroMatchPossible ||
            stackelm->alreadymatched ||
            stackelm->model->quant == XML_CQUANT_REP ||
            stackelm->model->quant == XML_CQUANT_OPT) {
            return -1;
        }
#ifdef TNC_DEBUG
        printf ("validation error\n");
#endif
        return 0;
    case XML_CTYPE_SEQ:
#ifdef TNC_DEBUG
        printf ("TncProbeElement XML_CTYPE_SEQ\n");
#endif
        if (stackelm->alreadymatched) {
            activeModel = &stackelm->model->children[stackelm->activeChild];
            if (activeModel->type == XML_CTYPE_NAME) {
                /* so this stackelement must be the topmost */
                if (activeModel->quant == XML_CQUANT_REP
                    || activeModel->quant == XML_CQUANT_PLUS) {
                    /* the last matched element is multiple, maybe it
                       matches again */
                    if (nameId == activeModel->nameId) {
#ifdef TNC_DEBUG
                        printf ("-->matched! child Nr. %d\n",
                                stackelm->activeChild);
#endif
                        /* stack and activeChild nr. are already OK, just
                           report success. */
                        return 1;
                    }
                }
            }
        }

        if (stackelm->alreadymatched) {
            seqstartindex = stackelm->activeChild + 1;
        }
        else {
            seqstartindex = 0;
        }
        /* This time zeroMatchPossible flags, if every of the remaining
           childs - that may every child, if !alreadymatched - doesn't
           must occur.  We assume, the (outstanding childs of, in case
           of alreadymatched) current stackelement model has only
           optional childs, and set to wrong, if we find any
           non-optional child */
        zeroMatchPossible = 1;
        for (i = seqstartindex; i < stackelm->model->numchildren; i++) {
            if ((&stackelm->model->children[i])->type == XML_CTYPE_NAME) {
                if ((&stackelm->model->children[i])->nameId == nameId) {
#ifdef TNC_DEBUG
                    printf ("-->matched! child Nr. %d\n",i);
#endif
                    (&tncdata->contentStack[myStackPtr])->activeChild = i;
                    (&tncdata->contentStack[myStackPtr])->alreadymatched = 1;
                    return 1;
                } else if ((&stackelm->model->children[i])->quant
                           == XML_CQUANT_NONE
                           || (&stackelm->model->children[i])->quant
                               == XML_CQUANT_PLUS) {
                    zeroMatchPossible = 0;
                    break;
                }
            } else {
                if (tncdata->contentStackPtr == tncdata->contentStackSize) {
                    tncdata->contentStack = (TNC_ContentStack *)
                        Tcl_Realloc ((char *)tncdata->contentStack,
                                     sizeof (TNC_Content *) * 2 *
                                     tncdata->contentStackSize);
                    tncdata->contentStackSize *= 2;
                }
                (&tncdata->contentStack[tncdata->contentStackPtr])->model =
                    &stackelm->model->children[i];
                tncdata->contentStack[tncdata->contentStackPtr].activeChild
                    = 0;
                tncdata->contentStack[tncdata->contentStackPtr].deep
                    = stackelm->deep + 1;
                tncdata->contentStack[tncdata->contentStackPtr].alreadymatched
                    = 0;
                tncdata->contentStackPtr++;
                result = TncProbeElement (nameId, tncdata);
                if (result == 1) {
                    (&tncdata->contentStack[myStackPtr])->activeChild = i;
                    (&tncdata->contentStack[myStackPtr])->alreadymatched = 1;
                    return 1;
                }
                tncdata->contentStackPtr--;
                if (result == 0) {
                    zeroMatchPossible = 0;
                    break;
                }
            }
        }
        if (!stackelm->alreadymatched) {
            if (zeroMatchPossible) {
                /* The stackelm hasn't matched, but don't have to
                   after all.  Return try further */
                return -1;
            } else {
                /* No previous match, but at least one child is
                   necessary. Return depends of the quant of the
                   entire seq */
                if (stackelm->model->quant == XML_CQUANT_NONE ||
                    stackelm->model->quant == XML_CQUANT_PLUS) {
                    /* DTD claims, the seq as to be there, but isn't */
                    return 0;
                } else {
                    /* The seq is optional */
                    return -1;
                }
            }
        }
        if (stackelm->alreadymatched) {
            if (!zeroMatchPossible) {
                /* Some child at the start of the seq has matched in
                   the past, but since zeroMatchPossible has changed
                   to zero, there must be a non-matching non-optional
                   child later. Error in document structure. */
                return 0;
            } else {
                /* OK, SEQ has matched befor. But after the last match, there
                   where no required (quant NONE or PLUS) childs. */
                if (stackelm->model->quant == XML_CQUANT_NONE ||
                    stackelm->model->quant == XML_CQUANT_OPT) {
                    /* The entire seq isn't multiple. Just look further. */
                    return -1;
                }
            }
        }
        /* The last untreated case is alreadymatched true,
           zeroMatchPossible (of the rest of the seq childs after the
           last match) true and the entire seq may be
           multiple. Therefore start again with activeChild = 0, to
           see, if the current nameId starts a repeated match of the
           seq.  By the way: zeroMatchPossible still has initial value
           1, therefor no second initialiation is needed */
        for (i = 0; i < seqstartindex; i++) {
            if ((&stackelm->model->children[i])->type == XML_CTYPE_NAME) {
                if ((&stackelm->model->children[i])->nameId == nameId) {
#ifdef TNC_DEBUG
                    printf ("-->matched! child Nr. %d\n",i);
#endif
                    (&tncdata->contentStack[myStackPtr])->activeChild = i;
                    (&tncdata->contentStack[myStackPtr])->alreadymatched = 1;
                    return 1;
                } else if ((&stackelm->model->children[i])->quant
                           == XML_CQUANT_NONE
                           || (&stackelm->model->children[i])->quant
                               == XML_CQUANT_PLUS) {
                    zeroMatchPossible = 0;
                    break;
                }
            } else {
                if (tncdata->contentStackPtr == tncdata->contentStackSize) {
                    tncdata->contentStack = (TNC_ContentStack *)
                        Tcl_Realloc ((char *)tncdata->contentStack,
                                     sizeof (TNC_Content *) * 2 *
                                     tncdata->contentStackSize);
                    tncdata->contentStackSize *= 2;
                }
                (&tncdata->contentStack[tncdata->contentStackPtr])->model =
                    &stackelm->model->children[i];
                tncdata->contentStack[tncdata->contentStackPtr].activeChild
                    = 0;
                tncdata->contentStack[tncdata->contentStackPtr].deep
                    = stackelm->deep + 1;
                tncdata->contentStack[tncdata->contentStackPtr].alreadymatched
                    = 0;
                tncdata->contentStackPtr++;
                result = TncProbeElement (nameId, tncdata);
                if (result) {
                    (&tncdata->contentStack[myStackPtr])->activeChild = i;
                    /* alreadymatched is already 1 */
                    return 1;
                }
                tncdata->contentStackPtr--;
                if (result == 0) {
                    /* OK, the seq doesn't match again. But since it have
                       already matched, this isn't return 0 but.. */
                    return -1;
                }
            }
        }
        /* seq doesn't match again and every seq child from the very first
           up to (not including) the last match aren't required. This last
           fact may be nice to know, but after all since the entire seq have
           matched already ... */
        return -1;
    case XML_CTYPE_NAME:
        /* NAME type dosen't occur at top level of a content model and is
           handled in some "shotcut" way directly in the CHOICE and SEQ cases.
           It's only here to pacify gcc -Wall. */
        printf ("error!!! - in TncProbeElement: XML_CTYPE_NAME shouldn't reached in any case.\n");
    default:
        printf ("error!!! - in TncProbeElement: unknown content type: %d\n",
                stackelm->model->type);
    }
    /* not reached */
    printf ("error!!! - in TncProbeElement: end of function reached.\n");
    return 0;
}

/*
 *----------------------------------------------------------------------------
 *
 * TncProbeAttribute --
 *
 *	This function checks, if the given attribute 
 *      and it's value are allowed for this element.
 *
 * Results:
 *	1 if the attribute name/value is OK,
 *      0 if not.
 *
 * Side effects:
 *	Eventually increments the required attributes counter.
 *
 *----------------------------------------------------------------------------
 */

static int
TncProbeAttribute (
    void *userData,
    Tcl_HashTable *elemAtts,
    char *attrName,
    char *attrValue,
    int *nrOfreq
)
{
    domReadInfo *tncdata = (domReadInfo *) userData;
    Tcl_HashEntry *entryPtr;
    TNC_AttDecl *attDecl;
    char *pc, *copy, save;
    int clen, i, start, hnew;
    TNC_EntityInfo *entityInfo;

    entryPtr = Tcl_FindHashEntry (elemAtts, attrName);
    if (!entryPtr) {
        signalNotValid (userData, TNC_ERROR_UNKNOWN_ATTRIBUTE);
        return 0;
    }
    /* NOTE: attribute uniqueness per element is a wellformed
               constrain and therefor done by expat. */
    attDecl = (TNC_AttDecl *) Tcl_GetHashValue (entryPtr);
    switch (attDecl->att_type) {
    case TNC_ATTTYPE_CDATA:
        if (attDecl->isrequired && attDecl->dflt) {
            if (strcmp (attDecl->dflt, attrValue) != 0) {
                signalNotValid (userData,
                                TNC_ERROR_WRONG_FIXED_ATTVALUE);
                return 0;
            }
        }
        break;

    case TNC_ATTTYPE_ID:
        pc = (char*)attrValue;
        clen = UTF8_CHAR_LEN (*pc);
        CHECK_UTF_CHARLENR (clen);
        if (!UTF8_GET_NAME_START (pc, clen)) {
            signalNotValid (userData, TNC_ERROR_NAME_REQUIRED);
        }
        pc += clen;
        while (1) {
            if (*pc == '\0') {
                break;
            }
            clen = UTF8_CHAR_LEN (*pc);
            CHECK_UTF_CHARLENR (clen);
            if (!UTF8_GET_NAMING_NMTOKEN (pc, clen)) {
                signalNotValid (userData, TNC_ERROR_NAME_REQUIRED);
                return 0;
            }
            pc += clen;
        }
        entryPtr = Tcl_CreateHashEntry (tncdata->ids, attrValue, &hnew);
        if (!hnew) {
            if (Tcl_GetHashValue (entryPtr)) {
                signalNotValid (userData,
                                TNC_ERROR_DUPLICATE_ID_VALUE);
                return 0;
            }
        }
        Tcl_SetHashValue (entryPtr, (char *) 1);
        break;

    case TNC_ATTTYPE_IDREF:
        /* Name type constraint "implicit" checked. If the
           referenced ID exists, the type must be OK, because the
           type of the ID's within the document are checked.
           If there isn't such an ID, it's an error anyway. */
        if (attrValue[0] == '\0') {
            signalNotValid (userData, TNC_ERROR_NAME_REQUIRED);
            return 0;
        }
        entryPtr = Tcl_CreateHashEntry (tncdata->ids, attrValue, &hnew);
        break;

    case TNC_ATTTYPE_IDREFS:
        if (attrValue[0] == '\0') {
            signalNotValid (userData, TNC_ERROR_NAMES_REQUIRED);
            return 0;
        }
        /* Due to attribute value normalization (xml rec 3.3.3) this
           is a simple list "ref ref ref ..." without leading or
           trailing spaces and exact one space between the refs. */
        start = i = 0;
        while (attrValue[i]) {
            if (attrValue[i] == ' ') {
                save = attrValue[i];
                attrValue[i] = '\0';
                entryPtr = Tcl_CreateHashEntry (tncdata->ids,
                                                &attrValue[start], &hnew);
                attrValue[i] = save;
                start = ++i;
                continue;
            }
            i++;
        }
        entryPtr = Tcl_CreateHashEntry (tncdata->ids, &attrValue[start], 
                                        &hnew);
        break;

    case TNC_ATTTYPE_ENTITY:
        /* There is a validity constraint requesting entity attributes
           values to be type Name. But if there would be an entity
           declaration that doesn't fit this constraint, expat would
           have already complained about the definition. So we go the
           easy way and just look up the att value. If it's declared,
           type must be OK, if not, it's an error anyway. */
        entryPtr = Tcl_FindHashEntry (tncdata->entityDecls, attrValue);
        if (!entryPtr) {
            signalNotValid (userData, TNC_ERROR_ENTITY_ATTRIBUTE);
            return 0;
        }
        entityInfo = (TNC_EntityInfo *) Tcl_GetHashValue (entryPtr);
        if (!entityInfo->is_notation) {
            signalNotValid (userData, TNC_ERROR_ENTITY_ATTRIBUTE);
            return 0;
        }
        break;

    case TNC_ATTTYPE_ENTITIES:
        /* Normalized by exapt; for type see comment to
           TNC_ATTTYPE_ENTITY */
        copy = tdomstrdup (attrValue);
        start = i = 0;
        while (1) {
            if (copy[i] == '\0') {
                entryPtr = Tcl_FindHashEntry (tncdata->entityDecls,
                                              &copy[start]);
                if (!entryPtr) {
                    signalNotValid (userData, TNC_ERROR_ENTITIES_ATTRIBUTE);
                    FREE (copy);
                    return 0;
                }
                entityInfo = (TNC_EntityInfo *) Tcl_GetHashValue (entryPtr);
                if (!entityInfo->is_notation) {
                    signalNotValid (userData, TNC_ERROR_ENTITIES_ATTRIBUTE);
                    FREE (copy);
                    return 0;
                }
                FREE (copy);
                break;
            }
            if (copy[i] == ' ') {
                copy[i] = '\0';
                entryPtr = Tcl_FindHashEntry (tncdata->entityDecls,
                                              &copy[start]);
                if (!entryPtr) {
                    signalNotValid (userData, TNC_ERROR_ENTITIES_ATTRIBUTE);
                    FREE (copy);
                    return 0;
                }
                entityInfo = (TNC_EntityInfo *) Tcl_GetHashValue (entryPtr);
                if (!entityInfo->is_notation) {
                    signalNotValid (userData, TNC_ERROR_ENTITIES_ATTRIBUTE);
                    FREE (copy);
                    return 0;
                }
                start = ++i;
                continue;
            }
            i++;
        }
        break;

    case TNC_ATTTYPE_NMTOKEN:
        /* We assume, that the UTF-8 representation of the value is
           valid (no partial chars, minimum encoding). This makes
           things a little more easy and faster. I guess (but
           haven't deeply checked - QUESTION -), expat would have
           already complained otherwise. */
        pc = (char*)attrValue;
        clen = 0;
        while (1) {
            if (*pc == '\0') {
                break;
            }
            clen = UTF8_CHAR_LEN (*pc);
            CHECK_UTF_CHARLENR (clen);
            if (!UTF8_GET_NAMING_NMTOKEN (pc, clen)) {
                signalNotValid (userData, TNC_ERROR_NMTOKEN_REQUIRED);
                return 0;
            }
            pc += clen;
        }
        if (!clen) 
            signalNotValid (userData, TNC_ERROR_NMTOKEN_REQUIRED);
        break;

    case TNC_ATTTYPE_NMTOKENS:
        pc = (char*)attrValue;
        clen = 0;
        while (1) {
            if (*pc == '\0') {
                break;
            }
            /* NMTOKENS are normalized by expat, so this should
               be secure. */
            if (*pc == ' ') {
                pc++;
            }
            clen = UTF8_CHAR_LEN (*pc);
            CHECK_UTF_CHARLENR (clen);
            if (!UTF8_GET_NAMING_NMTOKEN (pc, clen)) {
                signalNotValid (userData, TNC_ERROR_NMTOKEN_REQUIRED);
                return 0;
            }
            pc += clen;
        }
        if (!clen)
            signalNotValid (userData, TNC_ERROR_NMTOKEN_REQUIRED);
        break;

    case TNC_ATTTYPE_NOTATION:
        entryPtr = Tcl_FindHashEntry (attDecl->lookupTable, attrValue);
        if (!entryPtr) {
            signalNotValid (userData, TNC_ERROR_NOTATION_REQUIRED);
            return 0;
        }
        break;

    case TNC_ATTTYPE_ENUMERATION:
        if (!Tcl_FindHashEntry (attDecl->lookupTable, attrValue)) {
            signalNotValid (userData, TNC_ERROR_ENUM_ATT_WRONG_VALUE);
            return 0;
        }
        break;
    }

    if (attDecl->isrequired) {
        (*nrOfreq)++;
    }

    return 1;
}

/*
 *----------------------------------------------------------------------------
 *
 * TncProbeElementEnd --
 *
 *	This procedure checks, if the current content allows the
 *      the element to end here.
 *
 * Results:
 *	1 if element end is OK,
 *      0 if not.
 *
 * Side effects:
 *	Let the contentStackPtr point to the last current content
 *      model before the element had started.
 *
 *----------------------------------------------------------------------------
 */

static int
TncProbeElementEnd (
    domReadInfo *tncdata
)
{
    TNC_ContentStack stackelm;
    unsigned int i;
    int zeroMatchPossible, seqstartindex;

    stackelm = tncdata->contentStack[tncdata->contentStackPtr - 1];
    switch (stackelm.model->type) {
    case XML_CTYPE_MIXED:
    case XML_CTYPE_ANY:
    case XML_CTYPE_EMPTY:
        return 1;
    case XML_CTYPE_CHOICE:
        if (stackelm.alreadymatched) {
            return 1;
        }

        if (stackelm.model->quant == XML_CQUANT_REP ||
            stackelm.model->quant == XML_CQUANT_OPT) {
            return 1;
        }
        zeroMatchPossible = 0;
        for (i = 0; i < stackelm.model->numchildren; i++) {
            if ((&stackelm.model->children[i])->type == XML_CTYPE_NAME) {
                if ((&stackelm.model->children[i])->quant == XML_CQUANT_OPT ||
                    (&stackelm.model->children[i])->quant == XML_CQUANT_REP) {
                    zeroMatchPossible = 1;
                    break;
                }
            }
            else {
                if (tncdata->contentStackPtr == tncdata->contentStackSize) {
                    tncdata->contentStack = (TNC_ContentStack *)
                        Tcl_Realloc ((char *)tncdata->contentStack,
                                     sizeof (TNC_Content *) * 2 *
                                     tncdata->contentStackSize);
                    tncdata->contentStackSize *= 2;
                }
                (&tncdata->contentStack[tncdata->contentStackPtr])->model
                    = &stackelm.model->children[i];
                tncdata->contentStack[tncdata->contentStackPtr].activeChild
                    = 0;
                tncdata->contentStack[tncdata->contentStackPtr].deep
                    = stackelm.deep + 1;
                tncdata->contentStack[tncdata->contentStackPtr].alreadymatched
                    = 0;
                tncdata->contentStackPtr++;
                if (TncProbeElementEnd (tncdata)) {
                    zeroMatchPossible = 1;
                    tncdata->contentStackPtr--;
                    break;
                }
                tncdata->contentStackPtr--;
            }
        }
        if (zeroMatchPossible) {
            return 1;
        } else {
            return 0;
        }
    case XML_CTYPE_SEQ:
        if (!stackelm.alreadymatched) {
            if (stackelm.model->quant == XML_CQUANT_REP ||
                stackelm.model->quant == XML_CQUANT_OPT) {
                return 1;
            }
        }
        if (!stackelm.alreadymatched) {
            seqstartindex = 0;
        }
        else {
            seqstartindex = stackelm.activeChild + 1;
        }
        for (i = seqstartindex; i < stackelm.model->numchildren; i++) {
            if ((&stackelm.model->children[i])->type == XML_CTYPE_NAME) {
                if ((&stackelm.model->children[i])->quant == XML_CQUANT_OPT ||
                    (&stackelm.model->children[i])->quant == XML_CQUANT_REP) {
                    continue;
                } else {
                    return 0;
                }
            } else {
                if (tncdata->contentStackPtr == tncdata->contentStackSize) {
                    tncdata->contentStack = (TNC_ContentStack *)
                        Tcl_Realloc ((char *)tncdata->contentStack,
                                     sizeof (TNC_Content *) * 2 *
                                     tncdata->contentStackSize);
                    tncdata->contentStackSize *= 2;
                }
                (&tncdata->contentStack[tncdata->contentStackPtr])->model
                    = &stackelm.model->children[i];
                tncdata->contentStack[tncdata->contentStackPtr].activeChild
                    = 0;
                tncdata->contentStack[tncdata->contentStackPtr].deep
                    = stackelm.deep + 1;
                tncdata->contentStack[tncdata->contentStackPtr].alreadymatched
                    = 0;
                tncdata->contentStackPtr++;
                if (TncProbeElementEnd (tncdata)) {
                    tncdata->contentStackPtr--;
                    continue;
                }
                else {
                    tncdata->contentStackPtr--;
                    return 0;
                }
            }
        }
        return 1;
    case XML_CTYPE_NAME:
        /* NAME type dosen't occur at top level of a content model and is
           handled in some "shotcut" way directly in the CHOICE and SEQ cases.
           It's only here to pacify gcc -Wall. */
        fprintf (stderr, "error!!! - in TncProbeElementEnd: XML_CTYPE_NAME "
                 "shouldn't be reached in any case.\n");
    default:
        fprintf (stderr, "error!!! - in TncProbeElementEnd: unknown content "
                 "type: %d\n", stackelm.model->type);
        return 1;
    }
}
#endif

/*---------------------------------------------------------------------------
|   startElement
|
\--------------------------------------------------------------------------*/
static void
startElement(
1161
1162
1163
1164
1165
1166
1167











































































































































1168
1169
1170
1171
1172
1173
1174
            info->nextFeedbackPosition = 
                XML_GetCurrentByteIndex (info->parser) + info->feedbackAfter;
            Tcl_ResetResult (info->interp);
        }
    }

    DispatchPCDATA (info);











































































































































    
    h = Tcl_CreateHashEntry(&HASHTAB(info->document,tdom_tagNames), name,
                            &hnew);
    if (info->storeLineColumn) {
        node = (domNode*) domAlloc(sizeof(domNode)
                                    + sizeof(domLineColumn));
    } else {







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







2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
            info->nextFeedbackPosition = 
                XML_GetCurrentByteIndex (info->parser) + info->feedbackAfter;
            Tcl_ResetResult (info->interp);
        }
    }

    DispatchPCDATA (info);

#ifndef TDOM_NO_DTD_VALIDATION
    if (info->dtdvalidation) {
        domReadInfo *tncdata = info;
        Tcl_HashEntry *entryPtr;
        Tcl_HashTable *elemAtts;
        const char **atPtr;
        TNC_ElemAttInfo *elemAttInfo;
        TNC_Content *model;
        int result, nrOfreq, acceptNoDoctype = 0;

#ifdef TNC_DEBUG
        printf ("TncElementStartCommand name: %s\n", name);
#endif

        /* If the document doesn't have a doctype declaration, but the
           user have used the -useForeignDTD 1 feature, the collected
           data out of the provided DTD isn't postprocessed by 
           TncElementStartCommand. We do this now.
           NOTE: Since there wasn't a doctype declaration, there is no
           information available which element is expected to be the
           document element. Eventually it would be desirable, to set
           this somehow. For now, this means, that every valid subtree
           of the given DTD information is accepted.  */
        if (!tncdata->contentStackPtr && !tncdata->elemContentsRewriten) {
            TncEndDoctypeDeclHandler (userData);
            acceptNoDoctype = 1;
        }

        entryPtr = Tcl_FindHashEntry (tncdata->tagNames, name);
        if (!entryPtr) {
            signalNotValid (userData, TNC_ERROR_UNKNOWN_ELEMENT);
            return;
        }
        model = (TNC_Content *) Tcl_GetHashValue (entryPtr);

        switch (model->type) {
        case XML_CTYPE_MIXED:
        case XML_CTYPE_ANY:
            tncdata->skipWhiteCDATAs = 1;
            tncdata->ignorePCDATA = 1;
            break;
        case XML_CTYPE_EMPTY:
            tncdata->skipWhiteCDATAs = 0;
            break;
        case XML_CTYPE_CHOICE:
        case XML_CTYPE_SEQ:
            tncdata->skipWhiteCDATAs = 1;
            tncdata->ignorePCDATA = 0;
            break;
        case XML_CTYPE_NAME:
            break;
        }

        if (tncdata->contentStackPtr) {
            /* This is the normal case, within some content,
               at least the root element content. */
            while (1) {
                result = TncProbeElement (entryPtr, tncdata);
                if (result == -1) {
                    if (tncdata->contentStack[tncdata->contentStackPtr - 1].deep
                        == 0) {
                        signalNotValid (userData,
                                        TNC_ERROR_ELEMENT_NOT_ALLOWED_HERE);
                        return;
                    }
                    tncdata->contentStackPtr--;
                    continue;
                }
                if (result) {
                    break;
                }
                if (!result) {
                    signalNotValid (userData, TNC_ERROR_ELEMENT_NOT_ALLOWED_HERE);
                    return;
                }
            }
            if (tncdata->contentStackPtr == tncdata->contentStackSize) {
                tncdata->contentStackSize *= 2;
                tncdata->contentStack = (TNC_ContentStack *)
                    Tcl_Realloc ((char *)tncdata->contentStack,
                                 sizeof (TNC_Content *)*tncdata->contentStackSize);
            }
            (&tncdata->contentStack[tncdata->contentStackPtr])->model = model;
            (&tncdata->contentStack[tncdata->contentStackPtr])->activeChild = 0;
            (&tncdata->contentStack[tncdata->contentStackPtr])->deep = 0;
            (&tncdata->contentStack[tncdata->contentStackPtr])->alreadymatched = 0;
            tncdata->contentStackPtr++;
        } else {
            /* This is only in case of the root element */
            if (atts) {
                if (!tncdata->doctypeName) {
                    if (!acceptNoDoctype) {
                        signalNotValid (userData, TNC_ERROR_NO_DOCTYPE_DECL);
                        return;
                    }
                } else {
                    if (strcmp (tncdata->doctypeName, name) != 0) {
                        signalNotValid (userData, TNC_ERROR_WRONG_ROOT_ELEMENT);
                        return;
                    }
                }
            }
            (&(tncdata->contentStack)[0])->model = model;
            (&(tncdata->contentStack)[0])->activeChild = 0;
            (&(tncdata->contentStack)[0])->deep = 0;
            (&(tncdata->contentStack)[0])->alreadymatched = 0;
            tncdata->contentStackPtr++;
        }
    
        if (atts) {
            elemAttInfo = model->attInfo;
            if (!elemAttInfo) {
                if (atts[0] != NULL) {
                    signalNotValid (userData, TNC_ERROR_NO_ATTRIBUTES);
                    return;
                }
            } else {
                elemAtts = elemAttInfo->attributes;
                nrOfreq = 0;
                for (atPtr = atts; atPtr[0]; atPtr += 2) {
                    if (!TncProbeAttribute (userData, elemAtts, (char *) atPtr[0],
                                            (char *) atPtr[1], &nrOfreq))    
                        return;
                }
                if (nrOfreq != elemAttInfo->nrOfreq) {
                    signalNotValid (userData, 
                                    TNC_ERROR_MISSING_REQUIRED_ATTRIBUTE);
                    return;
                }
            }
        } else {
            tncdata->elemAttInfo = model->attInfo;
        }
#ifdef TNC_DEBUG
        printf ("TncElementStartCommand end\n");
#endif
    }
#endif
    
    h = Tcl_CreateHashEntry(&HASHTAB(info->document,tdom_tagNames), name,
                            &hnew);
    if (info->storeLineColumn) {
        node = (domNode*) domAlloc(sizeof(domNode)
                                    + sizeof(domLineColumn));
    } else {
1440
1441
1442
1443
1444
1445
1446






































































1447
1448
1449
1450
1451
1452
1453
    void        *userData,
    const char  *name
)
{
    domReadInfo  *info = userData;

    DispatchPCDATA (info);






































































    
    info->depth--;
    if (!info->ignorexmlns) {
        /* pop active namespaces */
        while ( (info->activeNSpos >= 0) &&
                (info->activeNS[info->activeNSpos].depth == info->depth) )
        {







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







2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
    void        *userData,
    const char  *name
)
{
    domReadInfo  *info = userData;

    DispatchPCDATA (info);

#ifndef TDOM_NO_DTD_VALIDATION
    if (info->dtdvalidation) {
        domReadInfo *tncdata = info;
        Tcl_HashEntry *entryPtr;
        Tcl_HashSearch search;

#ifdef TNC_DEBUG
        printf ("TncElementEndCommand start\n");
        printContentStack (tncdata);
#endif
        /* Calling XML_StopParser() in an element start event doesn't
         * always prevent expat from calling the element end handler.
         * (Yes, it's an expat thing, raised a few bugs upstream.) */
        if (tncdata->status == TCL_ERROR) return;
        while (1) {
            if (!TncProbeElementEnd (tncdata)) {
                signalNotValid (userData, TNC_ERROR_ELEMENT_CAN_NOT_END_HERE);
                return;
            }
            if (tncdata->contentStack[tncdata->contentStackPtr - 1].deep == 0) {
                break;
            }
            tncdata->contentStackPtr--;
        }
        /* Remove the content model of the closed element from the stack */
        tncdata->contentStackPtr--;
#ifdef TNC_DEBUG
        printf ("after removing ended element from the stack\n");
        printContentStack (tncdata);
#endif
        if (tncdata->contentStackPtr) {
            switch ((&tncdata->contentStack[tncdata->contentStackPtr - 1])->model->type) {
            case XML_CTYPE_MIXED:
            case XML_CTYPE_ANY:
                tncdata->skipWhiteCDATAs = 1;
                tncdata->ignorePCDATA = 1;
                break;
            case XML_CTYPE_EMPTY:
                tncdata->skipWhiteCDATAs = 0;
                break;
            case XML_CTYPE_CHOICE:
            case XML_CTYPE_SEQ:
            case XML_CTYPE_NAME:
                tncdata->skipWhiteCDATAs = 1;
                tncdata->ignorePCDATA = 0;
                break;
            }
        } else {
            /* This means, the root element is closed,
               therefor the place to check, if every IDREF points
               to a ID. */
            if (tncdata->idCheck) {
                for (entryPtr = Tcl_FirstHashEntry (tncdata->ids, &search);
                     entryPtr != NULL;
                     entryPtr = Tcl_NextHashEntry (&search)) {
#ifdef TNC_DEBUG
                    printf ("check id value %s\n",
                            Tcl_GetHashKey (tncdata->ids, entryPtr));
                    printf ("value %p\n", Tcl_GetHashValue (entryPtr));
#endif
                    if (!Tcl_GetHashValue (entryPtr)) {
                        signalNotValid (userData, TNC_ERROR_UNKNOWN_ID_REFERRED);
                        return;
                    }
                }
            }
        }
    }
#endif
    
    info->depth--;
    if (!info->ignorexmlns) {
        /* pop active namespaces */
        while ( (info->activeNSpos >= 0) &&
                (info->activeNS[info->activeNSpos].depth == info->depth) )
        {
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
























1485
1486
1487
1488
1489
1490
1491
/*---------------------------------------------------------------------------
|   characterDataHandler
|
\--------------------------------------------------------------------------*/
static void
characterDataHandler (
    void        *userData,
    const char  *s,
    int          len
)
{
    domReadInfo   *info = userData;

    Tcl_DStringAppend (info->cdata, s, len);
























    return;
    
}

/*---------------------------------------------------------------------------
|   startCDATA
|







|





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







2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
/*---------------------------------------------------------------------------
|   characterDataHandler
|
\--------------------------------------------------------------------------*/
static void
characterDataHandler (
    void        *userData,
    const char  *data,
    int          len
)
{
    domReadInfo   *info = userData;

    Tcl_DStringAppend (info->cdata, data, len);
#ifndef TDOM_NO_DTD_VALIDATION
    if (info->dtdvalidation) {
        domReadInfo *tncdata = info;
        int i;
        char *pc;

        if (!tncdata->skipWhiteCDATAs && len > 0) {
            signalNotValid (userData, TNC_ERROR_EMPTY_ELEMENT);
            return;
        }
        if (!tncdata->ignorePCDATA) {
            for (i = 0, pc = (char*)data; i < len; i++, pc++) {
                if ( (*pc == ' ')  ||
                     (*pc == '\n') ||
                     (*pc == '\r') ||
                     (*pc == '\t') ) {
                    continue;
                }
                signalNotValid (userData, TNC_ERROR_DISALLOWED_PCDATA);
                return;
            }
        }
    }
#endif    
    return;
    
}

/*---------------------------------------------------------------------------
|   startCDATA
|
2118
2119
2120
2121
2122
2123
2124





























































































































































































































































































































































































































































































































































































2125
2126
2127
2128
2129
2130
2131
    void *userData
)
{
    domReadInfo *info = (domReadInfo *) userData;

    info->insideDTD = 0;
}






























































































































































































































































































































































































































































































































































































/*---------------------------------------------------------------------------
|   domReadDocument
|
\--------------------------------------------------------------------------*/
domDocument *
domReadDocument (







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







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
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
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
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
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
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
    void *userData
)
{
    domReadInfo *info = (domReadInfo *) userData;

    info->insideDTD = 0;
}

#ifndef TDOM_NO_DTD_VALIDATION
/*
 *----------------------------------------------------------------------------
 *
 * TncElementDeclCommand --
 *
 *	This procedure is called for every element declaration.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Stores the tag name of the element in a lookup table.
 *
 *----------------------------------------------------------------------------
 */

static void
TncElementDeclCommand (
    void *userData,
    const char *name,
    XML_Content *model
)
{
    domReadInfo *tncdata = (domReadInfo *) userData;
    Tcl_HashEntry *entryPtr;
    int newPtr;
    unsigned int i, j;

    entryPtr = Tcl_CreateHashEntry (tncdata->tagNames, name, &newPtr);
    /* "No element type may be declared more than once." (rec. 3.2) */
    if (!newPtr) {
        XML_FreeContentModel (tncdata->parser, model);
        signalNotValid (userData, TNC_ERROR_DUPLICATE_ELEMENT_DECL);
        return;
    }
    /* "The same name must not appear more than once in a
        single mixed-content declaration." (rec. 3.2.2)
        NOTE: OK, OK, doing it this way may not be optimal or even fast
        in some cases. Please step in with a more fancy solution, if you
        feel the need. */
    if (model->type == XML_CTYPE_MIXED && model->quant == XML_CQUANT_REP) {
        for (i = 0; i < model->numchildren; i++) {
            for (j = i + 1; j < model->numchildren; j++) {
                if (strcmp ((&model->children[i])->name,
                            (&model->children[j])->name) == 0) {
                    XML_FreeContentModel (tncdata->parser, model);
                    signalNotValid (userData,
                                    TNC_ERROR_DUPLICATE_MIXED_ELEMENT);
                    return;
                }
            }
        }
    }
    Tcl_SetHashValue (entryPtr, model);
    return;
}

/*
 *----------------------------------------------------------------------------
 *
 * TncAttDeclCommand --
 *
 *	This procedure is called for *each* attribute in an XML
 *      ATTLIST declaration. It stores the attribute definition in
 *      an element specific hash table.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Stores the tag name of the element in a lookup table.
 *
 *----------------------------------------------------------------------------
 */

static void
TncAttDeclCommand (
    void       *userData,
    const char *elname,
    const char *attname,
    const char *att_type,
    const char *dflt,
    int         isrequired
)
{
    domReadInfo *tncdata = (domReadInfo *) userData;
    Tcl_HashEntry *entryPtr, *entryPtr1;
    Tcl_HashTable *elemAtts;
    TNC_ElemAttInfo *elemAttInfo;
    TNC_AttDecl *attDecl;
    TNC_EntityInfo *entityInfo;
    int newPtr, start, i, clen;
    char *copy;

    entryPtr = Tcl_CreateHashEntry (tncdata->attDefsTables, elname, &newPtr);
    if (newPtr) {
        elemAttInfo = (TNC_ElemAttInfo *) MALLOC (sizeof (TNC_ElemAttInfo));
        elemAtts = (Tcl_HashTable *) MALLOC (sizeof (Tcl_HashTable));
        Tcl_InitHashTable (elemAtts, TCL_STRING_KEYS);
        elemAttInfo->attributes = elemAtts;
        elemAttInfo->nrOfreq = 0;
        elemAttInfo->nrOfIdAtts = 0;
        Tcl_SetHashValue (entryPtr, elemAttInfo);
    } else {
        elemAttInfo = (TNC_ElemAttInfo *) Tcl_GetHashValue (entryPtr);
        elemAtts = elemAttInfo->attributes;
    }
    entryPtr = Tcl_CreateHashEntry (elemAtts, attname, &newPtr);
    /* Multiple Attribute declarations are allowed, but later declarations
       are ignored. See rec 3.3. */
    if (newPtr) {
        attDecl = (TNC_AttDecl *) MALLOC (sizeof (TNC_AttDecl));
        if (strcmp (att_type, "CDATA") == 0) {
            attDecl->att_type = TNC_ATTTYPE_CDATA;
        }
        else if (strcmp (att_type, "ID") == 0) {
            if (elemAttInfo->nrOfIdAtts) {
                signalNotValid (userData, TNC_ERROR_MORE_THAN_ONE_ID_ATT);
                return;
            }
            elemAttInfo->nrOfIdAtts++;
            if (dflt != NULL) {
                signalNotValid (userData, TNC_ERROR_ID_ATT_DEFAULT);
                return;
            }
            attDecl->att_type = TNC_ATTTYPE_ID;
        }
        else if (strcmp (att_type, "IDREF") == 0) {
            attDecl->att_type = TNC_ATTTYPE_IDREF;
        }
        else if (strcmp (att_type, "IDREFS") == 0) {
            attDecl->att_type = TNC_ATTTYPE_IDREFS;
        }
        else if (strcmp (att_type, "ENTITY") == 0) {
            attDecl->att_type = TNC_ATTTYPE_ENTITY;
        }
        else if (strcmp (att_type, "ENTITIES") == 0) {
            attDecl->att_type = TNC_ATTTYPE_ENTITIES;
        }
        else if (strcmp (att_type, "NMTOKEN") == 0) {
            attDecl->att_type = TNC_ATTTYPE_NMTOKEN;
        }
        else if (strcmp (att_type, "NMTOKENS") == 0) {
            attDecl->att_type = TNC_ATTTYPE_NMTOKENS;
        }
        else if (strncmp (att_type, "NOTATION(", 9) == 0) {
            /* This is a bit puzzling. expat returns something like
               <!NOTATION gif PUBLIC "gif">
               <!ATTLIST c type NOTATION (gif) #IMPLIED>
               as att_type "NOTATION(gif)". */
            attDecl->att_type = TNC_ATTTYPE_NOTATION;
            attDecl->lookupTable =
                (Tcl_HashTable *) MALLOC (sizeof (Tcl_HashTable));
            Tcl_InitHashTable (attDecl->lookupTable, TCL_STRING_KEYS);
            copy = tdomstrdup (att_type);
            start = i = 9;
            while (i) {
                if (copy[i] == ')') {
                    copy[i] = '\0';
#ifdef TNC_DEBUG
                    printf ("att type NOTATION: notation %s allowed\n",
                            &copy[start]);
#endif
                    Tcl_CreateHashEntry (attDecl->lookupTable,
                                                    &copy[start], &newPtr);
                    entryPtr1 = Tcl_CreateHashEntry (tncdata->notationDecls,
                                                    &copy[start], &newPtr);
#ifdef TNC_DEBUG
                    if (newPtr) {
                        printf ("up to now unknown NOTATION\n");
                    } else {
                        printf ("NOTATION already known\n");
                    }
#endif
                    FREE (copy);
                    break;
                }
                if (copy[i] == '|') {
                    copy[i] = '\0';
#ifdef TNC_DEBUG
                    printf ("att type NOTATION: notation %s allowed\n",
                            &copy[start]);
#endif
                    Tcl_CreateHashEntry (attDecl->lookupTable,
                                                    &copy[start], &newPtr);
                    entryPtr1 = Tcl_CreateHashEntry (tncdata->notationDecls,
                                                    &copy[start], &newPtr);
#ifdef TNC_DEBUG
                    if (newPtr) {
                        printf ("up to now unknown NOTATION\n");
                    } else {
                        printf ("NOTATION already known\n");
                    }
#endif
                    start = ++i;
                    continue;
                }
                clen = UTF8_CHAR_LEN (copy[i]);
                CHECK_UTF_CHARLEN_COPY (clen);
                if (!UTF8_GET_NAMING_NMTOKEN (&copy[i], clen)) {
                    signalNotValid (userData, TNC_ERROR_NMTOKEN_REQUIRED);
                    FREE (copy);
                    return;
                }
                i += clen;
            }
        }
        else {
            /* expat returns something like
               <!ATTLIST a type (  numbered
                   |bullets ) #IMPLIED>
               as att_type "(numbered|bullets)", e.g. in some
               "non-official" normalized way.
               Makes things easier for us. */
            attDecl->att_type = TNC_ATTTYPE_ENUMERATION;
            attDecl->lookupTable =
                (Tcl_HashTable *) MALLOC (sizeof (Tcl_HashTable));
            Tcl_InitHashTable (attDecl->lookupTable, TCL_STRING_KEYS);
            copy = tdomstrdup (att_type);
            start = i = 1;
            while (1) {
                if (copy[i] == ')') {
                    copy[i] = '\0';
                    Tcl_CreateHashEntry (attDecl->lookupTable,
                                                    &copy[start], &newPtr);
                    FREE (copy);
                    break;
                }
                if (copy[i] == '|') {
                    copy[i] = '\0';
                    Tcl_CreateHashEntry (attDecl->lookupTable,
                                                    &copy[start], &newPtr);
                    start = ++i;
                    continue;
                }
                clen = UTF8_CHAR_LEN (copy[i]);
                CHECK_UTF_CHARLEN_COPY (clen);
                if (!UTF8_GET_NAMING_NMTOKEN (&copy[i], clen)) {
                    signalNotValid (userData, TNC_ERROR_NMTOKEN_REQUIRED);
                    FREE (copy);
                    return;
                }
                i += clen;
            }
        }
        if (dflt != NULL) {
            switch (attDecl->att_type) {
            case TNC_ATTTYPE_ENTITY:
            case TNC_ATTTYPE_IDREF:
                clen = UTF8_CHAR_LEN (*dflt);
                CHECK_UTF_CHARLEN (clen);
                if (!UTF8_GET_NAME_START (dflt, clen)) {
                    signalNotValid (userData, TNC_ERROR_NAME_REQUIRED);
                    return;
                }
                i = clen;
                while (1) {
                    if (dflt[i] == '\0') {
                        break;
                    }
                    clen = UTF8_CHAR_LEN (dflt[i]);
                    CHECK_UTF_CHARLEN (clen);
                    if (!UTF8_GET_NAMING_NMTOKEN (&dflt[i], clen)) {
                        signalNotValid (userData, TNC_ERROR_NAME_REQUIRED);
                        return;
                    }
                    i += clen;
                }
                if (attDecl->att_type == TNC_ATTTYPE_ENTITY) {
                    entryPtr1 = Tcl_CreateHashEntry (tncdata->entityDecls,
                                                     dflt, &newPtr);
                    if (!newPtr) {
                        entityInfo =
                            (TNC_EntityInfo *) Tcl_GetHashValue (entryPtr1);
                        if (!entityInfo->is_notation) {
                            signalNotValid (userData,TNC_ERROR_ATT_ENTITY_DEFAULT_MUST_BE_DECLARED);
                        }
                    }
                }
                break;
            case TNC_ATTTYPE_IDREFS:
                start = i = 0;
                while (1) {
                    if (dflt[i] == '\0') {
                        break;
                    }
                    if (dflt[i] == ' ') {
                        start = ++i;
                    }
                    if (start == i) {
                        clen = UTF8_CHAR_LEN (dflt[i]);
                        CHECK_UTF_CHARLEN (clen);
                        if (!UTF8_GET_NAME_START (&dflt[i], clen)) {
                            signalNotValid (userData, TNC_ERROR_NAME_REQUIRED);
                            return;
                        }
                        i += clen;
                    }
                    else {
                        clen = UTF8_CHAR_LEN (dflt[i]);
                        CHECK_UTF_CHARLEN (clen);
                        if (!UTF8_GET_NAMING_NMTOKEN (&dflt[i], clen)) {
                            signalNotValid (userData, TNC_ERROR_NAME_REQUIRED);
                            return;
                        }
                        i += clen;
                    }
                }
                break;
            case TNC_ATTTYPE_ENTITIES:
                copy = tdomstrdup (dflt);
                start = i = 0;
                while (1) {
                    if (copy[i] == '\0') {
                        FREE (copy);
                        break;
                    }
                    if (copy[i] == ' ') {
                        copy[i] = '\0';
                        entryPtr1 = Tcl_CreateHashEntry (tncdata->entityDecls,
                                                         &copy[start],
                                                         &newPtr);
                        if (!newPtr) {
                            entityInfo =
                                (TNC_EntityInfo *) Tcl_GetHashValue (entryPtr1);
                            if (!entityInfo->is_notation) {
                                signalNotValid (userData,TNC_ERROR_ATT_ENTITY_DEFAULT_MUST_BE_DECLARED);
                            }
                        }
                        start = ++i;
                    }
                    if (start == i) {
                        clen = UTF8_CHAR_LEN (copy[i]);
                        CHECK_UTF_CHARLEN_COPY (clen);
                        if (!UTF8_GET_NAME_START (&copy[i], clen)) {
                            signalNotValid (userData, TNC_ERROR_NAME_REQUIRED);
                            FREE (copy);
                            return;
                        }
                        i += clen;
                    }
                    else {
                        clen = UTF8_CHAR_LEN (copy[i]);
                        CHECK_UTF_CHARLEN_COPY (clen);
                        if (!UTF8_GET_NAMING_NMTOKEN (&copy[i], clen)) {
                            signalNotValid (userData, TNC_ERROR_NAME_REQUIRED);
                            FREE (copy);
                            return;
                        }
                        i += clen;
                    }
                }
                break;
            case TNC_ATTTYPE_NMTOKEN:
                i = 0;
                while (1) {
                    if (dflt[i] == '\0') {
                        break;
                    }
                    clen = UTF8_CHAR_LEN (dflt[i]);
                    CHECK_UTF_CHARLEN (clen);
                    if (!UTF8_GET_NAMING_NMTOKEN (&dflt[i], clen)) {
                        signalNotValid (userData, TNC_ERROR_NMTOKEN_REQUIRED);
                        return;
                    }
                    i += clen;
                }
                if (!i) signalNotValid (userData, TNC_ERROR_NMTOKEN_REQUIRED);
                break;
            case TNC_ATTTYPE_NMTOKENS:
                i = 0;
                while (1) {
                    if (dflt[i] == '\0') {
                        break;
                    }
                    if (dflt[i] == ' ') {
                        i++;
                    }
                    clen = UTF8_CHAR_LEN (dflt[i]);
                    CHECK_UTF_CHARLEN (clen);
                    if (!UTF8_GET_NAMING_NMTOKEN (&dflt[i], clen)) {
                        signalNotValid (userData, TNC_ERROR_NMTOKEN_REQUIRED);
                        return;
                    }
                    i += clen;
                }
                if (!i) signalNotValid (userData, TNC_ERROR_NMTOKEN_REQUIRED);
                break;
            case TNC_ATTTYPE_NOTATION:
                if (!Tcl_FindHashEntry (attDecl->lookupTable, dflt)) {
                    signalNotValid (userData, TNC_ERROR_IMPOSSIBLE_DEFAULT);
                    return;
                }
            case TNC_ATTTYPE_ENUMERATION:
                if (!Tcl_FindHashEntry (attDecl->lookupTable, dflt)) {
                    signalNotValid (userData, TNC_ERROR_IMPOSSIBLE_DEFAULT);
                    return;
                }
            case TNC_ATTTYPE_CDATA:
            case TNC_ATTTYPE_ID:
                /* This both cases are only there, to pacify -Wall.
                   CDATA may have any allowed characters (and
                   everything else is detected by extpat).  ID's not
                   allowed to have defaults (handled above). */
                ;
            }
            attDecl->dflt = tdomstrdup (dflt);
        }
        else {
            attDecl->dflt = NULL;
        }
        if (isrequired) {
            elemAttInfo->nrOfreq++;
        }
        attDecl->isrequired = isrequired;
        Tcl_SetHashValue (entryPtr, attDecl);
    }
}

/*
 *----------------------------------------------------------------------------
 *
 * TncNotationDeclHandler --
 *
 *	This procedure is called for every notation declaration.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Stores the notationName in the notationDecls table with value
 *      one.
 *
 *----------------------------------------------------------------------------
 */

static void
TncNotationDeclHandler (
    void       *userData,
    const char *notationName,
    const char *base,
    const char *systemId,
    const char *publicId
)
{
    domReadInfo *tncdata = (domReadInfo *) userData;
    Tcl_HashEntry *entryPtr;
    int newPtr;

    entryPtr = Tcl_CreateHashEntry (tncdata->notationDecls,
                                    notationName,
                                    &newPtr);
#ifdef TNC_DEBUG
    printf ("Notation %s declared\n", notationName);
#endif
    Tcl_SetHashValue (entryPtr, (char *) 1);
}

/*
 *----------------------------------------------------------------------------
 *
 * TncFreeTncModel --
 *
 *	This helper procedure frees recursively TNC_Contents.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Frees memory.
 *
 *----------------------------------------------------------------------------
 */

static void
TncFreeTncModel (
    TNC_Content *tmodel
)
{
    unsigned int i;

    if (tmodel->children) {
        for (i = 0; i < tmodel->numchildren; i++) {
            TncFreeTncModel (&tmodel->children[i]);
        }
        FREE ((char *) tmodel->children);
    }
}

static void
TncFreeValidationData (
    domReadInfo *info
    )
{
    Tcl_HashEntry *entryPtr, *attentryPtr;
    Tcl_HashSearch search, attsearch;
    TNC_Content *model;
    TNC_ElemAttInfo *elemAttInfo;
    TNC_EntityInfo *entityInfo;
    TNC_AttDecl *attDecl;
    
    if (!info->dtdvalidation) return;
    
    entryPtr = Tcl_FirstHashEntry (info->tagNames, &search);
    while (entryPtr) {
        model = Tcl_GetHashValue (entryPtr);
        if (info->elemContentsRewriten) {
            if (model) {
                TncFreeTncModel (model);
                FREE ((char *) model);
            }
        } else {
            XML_FreeContentModel(info->parser, (XML_Content *)model);
        }
        entryPtr = Tcl_NextHashEntry (&search);
    }
    Tcl_DeleteHashTable (info->tagNames);
    entryPtr = Tcl_FirstHashEntry (info->attDefsTables, &search);
    while (entryPtr) {
        elemAttInfo = Tcl_GetHashValue (entryPtr);
        if (!elemAttInfo) {
            entryPtr = Tcl_NextHashEntry (&search);
            continue;
        }
        attentryPtr = Tcl_FirstHashEntry (elemAttInfo->attributes, &attsearch);
        while (attentryPtr) {
            attDecl = Tcl_GetHashValue (attentryPtr);
            if (attDecl) {
                if (attDecl->att_type == TNC_ATTTYPE_NOTATION ||
                    attDecl->att_type == TNC_ATTTYPE_ENUMERATION) {
                    Tcl_DeleteHashTable (attDecl->lookupTable);
                    FREE ((char *) attDecl->lookupTable);
                }
                if (attDecl->dflt) {
                    FREE (attDecl->dflt);
                }
                FREE ((char *) attDecl);
            }
            attentryPtr = Tcl_NextHashEntry (&attsearch);
        }
        Tcl_DeleteHashTable (elemAttInfo->attributes);
        FREE ((char *) elemAttInfo->attributes);
        FREE ((char *) elemAttInfo);
        entryPtr = Tcl_NextHashEntry (&search);
    }
    Tcl_DeleteHashTable (info->attDefsTables);
    entryPtr = Tcl_FirstHashEntry (info->entityDecls, &search);
    while (entryPtr) {
        entityInfo = Tcl_GetHashValue (entryPtr);
        if (entityInfo) {
            if (entityInfo->is_notation) {
                FREE (entityInfo->notationName);
            }
            FREE ((char *) entityInfo);
        }
        entryPtr = Tcl_NextHashEntry (&search);
    }
    Tcl_DeleteHashTable (info->entityDecls);
    Tcl_DeleteHashTable (info->notationDecls);
    Tcl_DeleteHashTable (info->ids);
    if (info->doctypeName) {
        FREE (info->doctypeName);
    }
    FREE ((char *) info->tagNames);
    FREE ((char *) info->attDefsTables);
    FREE ((char *) info->entityDecls);
    FREE ((char *) info->notationDecls);
    FREE ((char *) info->ids);
    FREE ((char *) info->contentStack);
}
#endif

/*---------------------------------------------------------------------------
|   domReadDocument
|
\--------------------------------------------------------------------------*/
domDocument *
domReadDocument (
2139
2140
2141
2142
2143
2144
2145



2146
2147
2148
2149
2150
2151
2152
    int         feedbackAfter,
    Tcl_Obj    *feedbackCmd,
    Tcl_Channel channel,
    const char *baseurl,
    Tcl_Obj    *extResolver,
    int         useForeignDTD,
    int         paramEntityParsing,



    Tcl_Interp *interp,
    int        *resultcode
)
{
    int             done, tclLen;
    enum XML_Status status;
    size_t          len;







>
>
>







4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
    int         feedbackAfter,
    Tcl_Obj    *feedbackCmd,
    Tcl_Channel channel,
    const char *baseurl,
    Tcl_Obj    *extResolver,
    int         useForeignDTD,
    int         paramEntityParsing,
#ifndef TDOM_NO_DTD_VALIDATION
    int         dtdvalidation,
#endif
    Tcl_Interp *interp,
    int        *resultcode
)
{
    int             done, tclLen;
    enum XML_Status status;
    size_t          len;
2185
2186
2187
2188
2189
2190
2191


2192


























2193
2194
2195
2196
2197
2198
2199
                                                       * info.activeNSsize);
    info.baseURIstackPos      = 0;
    info.baseURIstackSize     = INITIAL_BASEURISTACK_SIZE;
    info.baseURIstack         = (domActiveBaseURI*) 
        MALLOC (sizeof(domActiveBaseURI) * info.baseURIstackSize);
    info.insideDTD            = 0;
    info.status               = 0;





























    XML_SetUserData(parser, &info);
    XML_SetBase (parser, baseurl);
    /* We must use XML_GetBase(), because XML_SetBase copies the baseURI,
       and we want to compare the pointers */
    info.baseURIstack[0].baseURI = XML_GetBase (parser);
    info.baseURIstack[0].depth = 0;
    XML_UseForeignDTD (parser, (unsigned char) useForeignDTD);







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







4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
                                                       * info.activeNSsize);
    info.baseURIstackPos      = 0;
    info.baseURIstackSize     = INITIAL_BASEURISTACK_SIZE;
    info.baseURIstack         = (domActiveBaseURI*) 
        MALLOC (sizeof(domActiveBaseURI) * info.baseURIstackSize);
    info.insideDTD            = 0;
    info.status               = 0;
#ifndef TDOM_NO_DTD_VALIDATION
    info.dtdvalidation        = dtdvalidation;
    
    if (dtdvalidation) {
        info.tagNames = (Tcl_HashTable *) MALLOC (sizeof (Tcl_HashTable));
        Tcl_InitHashTable (info.tagNames, TCL_STRING_KEYS);
        info.elemContentsRewriten = 0;
        info.dtdstatus = 0;
        info.idCheck = 1;
        info.attDefsTables = 
            (Tcl_HashTable *) MALLOC (sizeof (Tcl_HashTable));
        Tcl_InitHashTable (info.attDefsTables, TCL_STRING_KEYS);
        info.entityDecls = 
            (Tcl_HashTable *) MALLOC (sizeof (Tcl_HashTable));
        Tcl_InitHashTable (info.entityDecls, TCL_STRING_KEYS);
        info.notationDecls =
            (Tcl_HashTable *) MALLOC (sizeof (Tcl_HashTable));
        Tcl_InitHashTable (info.notationDecls, TCL_STRING_KEYS);
        info.ids = (Tcl_HashTable *) MALLOC (sizeof (Tcl_HashTable));
        Tcl_InitHashTable (info.ids, TCL_STRING_KEYS);
        info.doctypeName = NULL;
        info.skipWhiteCDATAs = 1;
        info.ignorePCDATA = 0;
        info.contentStack = (TNC_ContentStack *)
            MALLOC (sizeof (TNC_ContentStack) * TNC_INITCONTENTSTACKSIZE);
        info.contentStackSize = TNC_INITCONTENTSTACKSIZE;
        info.contentStackPtr = 0;
    }
#endif    
    XML_SetUserData(parser, &info);
    XML_SetBase (parser, baseurl);
    /* We must use XML_GetBase(), because XML_SetBase copies the baseURI,
       and we want to compare the pointers */
    info.baseURIstack[0].baseURI = XML_GetBase (parser);
    info.baseURIstack[0].depth = 0;
    XML_UseForeignDTD (parser, (unsigned char) useForeignDTD);
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
    XML_SetParamEntityParsing (parser, 
                             (enum XML_ParamEntityParsing) paramEntityParsing);
    XML_SetDoctypeDeclHandler (parser, startDoctypeDeclHandler,
                               endDoctypeDeclHandler);
    if (keepCDATA) {
        XML_SetCdataSectionHandler(parser, startCDATA, endCDATA);
    }
    






    if (channel == NULL) {
        status = XML_Parse(parser, xml, length, 1);
        switch (status) {
        case XML_STATUS_SUSPENDED:
            DBG(fprintf(stderr, "XML_STATUS_SUSPENDED\n");)
            if (info.status == TCL_BREAK) {
                Tcl_ResetResult(interp);
            }
            /* fall throu */
        case XML_STATUS_ERROR:
            DBG(fprintf(stderr, "XML_STATUS_ERROR\n");)
            FREE ( info.activeNS );
            FREE ( info.baseURIstack );
            Tcl_DStringFree (info.cdata);
            FREE ( info.cdata);



            domFreeDocument (doc, NULL, NULL);
            *resultcode = info.status;
            return NULL;
        case XML_STATUS_OK:
            break;
        }
    } else {
        Tcl_DStringInit (&dStr);
        if (Tcl_GetChannelOption (interp, channel, "-encoding", &dStr) != TCL_OK) {
            FREE ( (char*) info.activeNS );
            FREE ( info.baseURIstack );
            Tcl_DStringFree (info.cdata);
            FREE ( info.cdata);



            domFreeDocument (doc, NULL, NULL);
            *resultcode = info.status;
            return NULL;
        }
        if (strcmp (Tcl_DStringValue (&dStr), "utf-8")==0 ) useBinary = 1;
        else useBinary = 0;
        Tcl_DStringFree (&dStr);







|
>
>
>
>
|
>




|










>
>
>













>
>
>







4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
    XML_SetParamEntityParsing (parser, 
                             (enum XML_ParamEntityParsing) paramEntityParsing);
    XML_SetDoctypeDeclHandler (parser, startDoctypeDeclHandler,
                               endDoctypeDeclHandler);
    if (keepCDATA) {
        XML_SetCdataSectionHandler(parser, startCDATA, endCDATA);
    }
#ifndef TDOM_NO_DTD_VALIDATION
    if (dtdvalidation) {
        XML_SetElementDeclHandler (parser, TncElementDeclCommand);
        XML_SetAttlistDeclHandler (parser, TncAttDeclCommand);
        XML_SetNotationDeclHandler (parser, TncNotationDeclHandler);
    }
#endif
    if (channel == NULL) {
        status = XML_Parse(parser, xml, length, 1);
        switch (status) {
        case XML_STATUS_SUSPENDED:
            DBG(fprintf(stderr, "XML_STATUS_SUSPENDED\n"));
            if (info.status == TCL_BREAK) {
                Tcl_ResetResult(interp);
            }
            /* fall throu */
        case XML_STATUS_ERROR:
            DBG(fprintf(stderr, "XML_STATUS_ERROR\n");)
            FREE ( info.activeNS );
            FREE ( info.baseURIstack );
            Tcl_DStringFree (info.cdata);
            FREE ( info.cdata);
#ifndef TDOM_NO_DTD_VALIDATION
            if (info.dtdvalidation) TncFreeValidationData (&info);
#endif
            domFreeDocument (doc, NULL, NULL);
            *resultcode = info.status;
            return NULL;
        case XML_STATUS_OK:
            break;
        }
    } else {
        Tcl_DStringInit (&dStr);
        if (Tcl_GetChannelOption (interp, channel, "-encoding", &dStr) != TCL_OK) {
            FREE ( (char*) info.activeNS );
            FREE ( info.baseURIstack );
            Tcl_DStringFree (info.cdata);
            FREE ( info.cdata);
#ifndef TDOM_NO_DTD_VALIDATION
            if (info.dtdvalidation) TncFreeValidationData (&info);
#endif
            domFreeDocument (doc, NULL, NULL);
            *resultcode = info.status;
            return NULL;
        }
        if (strcmp (Tcl_DStringValue (&dStr), "utf-8")==0 ) useBinary = 1;
        else useBinary = 0;
        Tcl_DStringFree (&dStr);
2263
2264
2265
2266
2267
2268
2269



2270
2271
2272
2273
2274
2275
2276
                    /* fall throu */
                case XML_STATUS_ERROR:
                    DBG(fprintf(stderr, "XML_STATUS_ERROR\n");)
                    FREE ( info.activeNS );
                    FREE ( info.baseURIstack );
                    Tcl_DStringFree (info.cdata);
                    FREE ( info.cdata);



                    domFreeDocument (doc, NULL, NULL);
                    *resultcode = info.status;
                    return NULL;
                case XML_STATUS_OK:
                    break;
                }
            } while (!done);







>
>
>







4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
                    /* fall throu */
                case XML_STATUS_ERROR:
                    DBG(fprintf(stderr, "XML_STATUS_ERROR\n");)
                    FREE ( info.activeNS );
                    FREE ( info.baseURIstack );
                    Tcl_DStringFree (info.cdata);
                    FREE ( info.cdata);
#ifndef TDOM_NO_DTD_VALIDATION
                    if (info.dtdvalidation) TncFreeValidationData (&info);
#endif
                    domFreeDocument (doc, NULL, NULL);
                    *resultcode = info.status;
                    return NULL;
                case XML_STATUS_OK:
                    break;
                }
            } while (!done);
2291
2292
2293
2294
2295
2296
2297



2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312



2313
2314
2315
2316
2317
2318
2319
2320
                    /* fall throu */
                case XML_STATUS_ERROR:
                    DBG(fprintf(stderr, "XML_STATUS_ERROR\n");)
                    FREE ( info.activeNS );
                    FREE ( info.baseURIstack );
                    Tcl_DStringFree (info.cdata);
                    FREE ( info.cdata);



                    domFreeDocument (doc, NULL, NULL);
                    Tcl_DecrRefCount (bufObj);
                    *resultcode = info.status;
                    return NULL;
                case XML_STATUS_OK:
                    break;
                }
            } while (!done);
            Tcl_DecrRefCount (bufObj);
        }
    }
    FREE ( info.activeNS );
    FREE ( info.baseURIstack );
    Tcl_DStringFree (info.cdata);
    FREE ( info.cdata);




    domSetDocumentElement (doc);

    return doc;
}


#endif /* ifndef TDOM_NO_EXPAT */







>
>
>















>
>
>
|







4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
                    /* fall throu */
                case XML_STATUS_ERROR:
                    DBG(fprintf(stderr, "XML_STATUS_ERROR\n");)
                    FREE ( info.activeNS );
                    FREE ( info.baseURIstack );
                    Tcl_DStringFree (info.cdata);
                    FREE ( info.cdata);
#ifndef TDOM_NO_DTD_VALIDATION
                    if (info.dtdvalidation) TncFreeValidationData (&info);
#endif
                    domFreeDocument (doc, NULL, NULL);
                    Tcl_DecrRefCount (bufObj);
                    *resultcode = info.status;
                    return NULL;
                case XML_STATUS_OK:
                    break;
                }
            } while (!done);
            Tcl_DecrRefCount (bufObj);
        }
    }
    FREE ( info.activeNS );
    FREE ( info.baseURIstack );
    Tcl_DStringFree (info.cdata);
    FREE ( info.cdata);
#ifndef TDOM_NO_DTD_VALIDATION
    if (info.dtdvalidation) TncFreeValidationData (&info);
#endif
    
    domSetDocumentElement (doc);

    return doc;
}


#endif /* ifndef TDOM_NO_EXPAT */
5167
5168
5169
5170
5171
5172
5173



5174
5175
5176
5177
5178
5179
5180
    int               activeNSsize;
    int               activeNSpos;
    domActiveNS      *activeNS;
    int               baseURIstackSize;
    int               baseURIstackPos;
    domActiveBaseURI *baseURIstack;
    int               insideDTD;



    /* Now the tdom cmd specific elements */
    int               tdomStatus;
    Tcl_Obj          *extResolver;

} tdomCmdReadInfo;

int tcldom_returnDocumentObj (Tcl_Interp *interp, 







>
>
>







7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
    int               activeNSsize;
    int               activeNSpos;
    domActiveNS      *activeNS;
    int               baseURIstackSize;
    int               baseURIstackPos;
    domActiveBaseURI *baseURIstack;
    int               insideDTD;
#ifndef TDOM_NO_DTD_VALIDATION
    int               dtdvalidation;
#endif
    /* Now the tdom cmd specific elements */
    int               tdomStatus;
    Tcl_Obj          *extResolver;

} tdomCmdReadInfo;

int tcldom_returnDocumentObj (Tcl_Interp *interp, 
5239
5240
5241
5242
5243
5244
5245



5246
5247
5248
5249
5250
5251
5252
    info->feedbackAfter     = 0;
    info->ignorexmlns       = 0;
    Tcl_DStringSetLength (info->cdata, 0);
    info->nextFeedbackPosition = info->feedbackAfter;
    info->interp            = interp;
    info->activeNSpos       = -1;
    info->insideDTD         = 0;



    info->baseURIstackPos   = 0;
    info->tdomStatus        = 0;

}

void
tdom_initParseProc (







>
>
>







7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
    info->feedbackAfter     = 0;
    info->ignorexmlns       = 0;
    Tcl_DStringSetLength (info->cdata, 0);
    info->nextFeedbackPosition = info->feedbackAfter;
    info->interp            = interp;
    info->activeNSpos       = -1;
    info->insideDTD         = 0;
#ifndef TDOM_NO_DTD_VALIDATION
    info->dtdvalidation     = 0;
#endif            
    info->baseURIstackPos   = 0;
    info->tdomStatus        = 0;

}

void
tdom_initParseProc (
5376
5377
5378
5379
5380
5381
5382



5383
5384
5385
5386
5387
5388
5389
        info->activeNS          = 
            (domActiveNS*) MALLOC(sizeof(domActiveNS) * info->activeNSsize);
        info->baseURIstackPos   = 0;
        info->baseURIstackSize  = INITIAL_BASEURISTACK_SIZE;
        info->baseURIstack      = (domActiveBaseURI*) 
            MALLOC (sizeof(domActiveBaseURI) * info->baseURIstackSize);
        info->insideDTD         = 0;



        info->tdomStatus        = 0;
        info->extResolver       = NULL;

        handlerSet->userData    = info;

        CHandlerSetInstall (interp, objv[1], handlerSet);
        break;







>
>
>







7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
        info->activeNS          = 
            (domActiveNS*) MALLOC(sizeof(domActiveNS) * info->activeNSsize);
        info->baseURIstackPos   = 0;
        info->baseURIstackSize  = INITIAL_BASEURISTACK_SIZE;
        info->baseURIstack      = (domActiveBaseURI*) 
            MALLOC (sizeof(domActiveBaseURI) * info->baseURIstackSize);
        info->insideDTD         = 0;
#ifndef TDOM_NO_DTD_VALIDATION
        info->dtdvalidation     = 0;
#endif
        info->tdomStatus        = 0;
        info->extResolver       = NULL;

        handlerSet->userData    = info;

        CHandlerSetInstall (interp, objv[1], handlerSet);
        break;

Changes to generic/dom.h.

723
724
725
726
727
728
729



730
731
732
733
734
735
736
                                  int   feedbackAfter,
                                  Tcl_Obj *feedbackCmd,
                                  Tcl_Channel channel,
                                  const char *baseurl,
                                  Tcl_Obj *extResolver,
                                  int   useForeignDTD,
                                  int   paramEntityParsing,



                                  Tcl_Interp *interp,
                                  int  *status);

void           domFreeDocument   (domDocument *doc, 
                                  domFreeCallback freeCB, 
                                  void * clientData);








>
>
>







723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
                                  int   feedbackAfter,
                                  Tcl_Obj *feedbackCmd,
                                  Tcl_Channel channel,
                                  const char *baseurl,
                                  Tcl_Obj *extResolver,
                                  int   useForeignDTD,
                                  int   paramEntityParsing,
#ifndef TDOM_NO_DTD_VALIDATION
                                  int   dtdvalidation,
#endif
                                  Tcl_Interp *interp,
                                  int  *status);

void           domFreeDocument   (domDocument *doc, 
                                  domFreeCallback freeCB, 
                                  void * clientData);

Changes to generic/domxslt.c.

5788
5789
5790
5791
5792
5793
5794
5795




5796
5797
5798
5799
5800
5801
5802
        extResolver = Tcl_NewStringObj(xsltDoc->extResolver, -1);
        Tcl_IncrRefCount (extResolver);
    }
    /* keep white space, no fiddling with the encoding (is this
       a good idea?) */
    doc = domReadDocument (parser, xmlstring, len, 0, 0, storeLineColumn,
                           0, 0, NULL, chan, extbase, extResolver, 0, 
                           (int) XML_PARAM_ENTITY_PARSING_ALWAYS, interp,




                           &resultcode);
    if (xsltDoc->extResolver) {
        Tcl_DecrRefCount (extResolver);
    }
    if (doc == NULL) {
        DBG(fprintf (stderr, "parse error, str len %d, xmlstring: -->%s<--\n",
                     strlen (xmlstring), xmlstring);)







|
>
>
>
>







5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
        extResolver = Tcl_NewStringObj(xsltDoc->extResolver, -1);
        Tcl_IncrRefCount (extResolver);
    }
    /* keep white space, no fiddling with the encoding (is this
       a good idea?) */
    doc = domReadDocument (parser, xmlstring, len, 0, 0, storeLineColumn,
                           0, 0, NULL, chan, extbase, extResolver, 0, 
                           (int) XML_PARAM_ENTITY_PARSING_ALWAYS,
#ifndef TDOM_NO_DTD_VALIDATION
                           0,
#endif
                           interp,
                           &resultcode);
    if (xsltDoc->extResolver) {
        Tcl_DecrRefCount (extResolver);
    }
    if (doc == NULL) {
        DBG(fprintf (stderr, "parse error, str len %d, xmlstring: -->%s<--\n",
                     strlen (xmlstring), xmlstring);)

Changes to generic/tcldom.c.

1221
1222
1223
1224
1225
1226
1227



1228
1229
1230
1231
1232
1233
1234
                          0,
                          NULL,
                          NULL,
                          NULL,
                          extResolver,
                          0,
                          (int) XML_PARAM_ENTITY_PARSING_ALWAYS,



                          interp,
                          &resultcode);
    if (extResolver) {
        Tcl_DecrRefCount(extResolver);
    }
    if (doc == NULL) {
        char s[50];







>
>
>







1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
                          0,
                          NULL,
                          NULL,
                          NULL,
                          extResolver,
                          0,
                          (int) XML_PARAM_ENTITY_PARSING_ALWAYS,
#ifndef TDOM_NO_DTD_VALIDATION
                          0,
#endif
                          interp,
                          &resultcode);
    if (extResolver) {
        Tcl_DecrRefCount(extResolver);
    }
    if (doc == NULL) {
        char s[50];
6155
6156
6157
6158
6159
6160
6161



6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178




6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189



6190
6191
6192
6193
6194
6195
6196
    int          takeGUMBOParser     = 0;
    int          setVariable         = 0;
    int          ignorexmlns         = 0;
    int          feedbackAfter       = 0;
    int          useForeignDTD       = 0;
    int          paramEntityParsing  = (int)XML_PARAM_ENTITY_PARSING_ALWAYS;
    int          keepCDATA           = 0;



    int          status              = 0;
    domDocument *doc;
    Tcl_Obj     *newObjName = NULL;
    XML_Parser   parser;
    Tcl_Channel  chan = (Tcl_Channel) NULL;
    Tcl_CmdInfo  cmdInfo;

    static const char *parseOptions[] = {
        "-keepEmpties",           "-simple",        "-html",
        "-feedbackAfter",         "-channel",       "-baseurl",
        "-externalentitycommand", "-useForeignDTD", "-paramentityparsing",
        "-feedbackcmd",           "-json",          "-jsonroot",
#ifdef TDOM_HAVE_GUMBO
        "-html5",
#endif
        "-jsonmaxnesting",        "-ignorexmlns",   "--",
        "-keepCDATA",                NULL




    };
    enum parseOption {
        o_keepEmpties,            o_simple,         o_html,
        o_feedbackAfter,          o_channel,        o_baseurl,
        o_externalentitycommand,  o_useForeignDTD,  o_paramentityparsing,
        o_feedbackcmd,            o_json,           o_jsonroot,
#ifdef TDOM_HAVE_GUMBO
        o_htmlfive,
#endif
        o_jsonmaxnesting,         o_ignorexmlns,    o_LAST,
        o_keepCDATA



    };

    static const char *paramEntityParsingValues[] = {
        "always",
        "never",
        "notstandalone",
        (char *) NULL







>
>
>
















|
>
>
>
>











>
>
>







6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
    int          takeGUMBOParser     = 0;
    int          setVariable         = 0;
    int          ignorexmlns         = 0;
    int          feedbackAfter       = 0;
    int          useForeignDTD       = 0;
    int          paramEntityParsing  = (int)XML_PARAM_ENTITY_PARSING_ALWAYS;
    int          keepCDATA           = 0;
#ifndef TDOM_NO_DTD_VALIDATION
    int          dtdvalidation       = 0;
#endif
    int          status              = 0;
    domDocument *doc;
    Tcl_Obj     *newObjName = NULL;
    XML_Parser   parser;
    Tcl_Channel  chan = (Tcl_Channel) NULL;
    Tcl_CmdInfo  cmdInfo;

    static const char *parseOptions[] = {
        "-keepEmpties",           "-simple",        "-html",
        "-feedbackAfter",         "-channel",       "-baseurl",
        "-externalentitycommand", "-useForeignDTD", "-paramentityparsing",
        "-feedbackcmd",           "-json",          "-jsonroot",
#ifdef TDOM_HAVE_GUMBO
        "-html5",
#endif
        "-jsonmaxnesting",        "-ignorexmlns",   "--",
        "-keepCDATA",
#ifndef TDOM_NO_DTD_VALIDATION
        "-dtdvalidation",
#endif
        NULL
    };
    enum parseOption {
        o_keepEmpties,            o_simple,         o_html,
        o_feedbackAfter,          o_channel,        o_baseurl,
        o_externalentitycommand,  o_useForeignDTD,  o_paramentityparsing,
        o_feedbackcmd,            o_json,           o_jsonroot,
#ifdef TDOM_HAVE_GUMBO
        o_htmlfive,
#endif
        o_jsonmaxnesting,         o_ignorexmlns,    o_LAST,
        o_keepCDATA
#ifndef TDOM_NO_DTD_VALIDATION
        ,o_dtdvalidation
#endif
    };

    static const char *paramEntityParsingValues[] = {
        "always",
        "never",
        "notstandalone",
        (char *) NULL
6408
6409
6410
6411
6412
6413
6414






6415
6416
6417
6418
6419
6420
6421
                        
        case o_LAST:
            objv++;  objc--; break;
            
        case o_keepCDATA:
            keepCDATA = 1;
            objv++;  objc--; break;






            
        }
        if ((enum parseOption) optionIndex == o_LAST) break;
    }

    if (feedbackAfter && !feedbackCmd) {
        if (!Tcl_GetCommandInfo(interp, "::dom::domParseFeedback", 







>
>
>
>
>
>







6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
                        
        case o_LAST:
            objv++;  objc--; break;
            
        case o_keepCDATA:
            keepCDATA = 1;
            objv++;  objc--; break;
            
#ifndef TDOM_NO_DTD_VALIDATION
        case o_dtdvalidation:
            dtdvalidation = 1;
            objv++;  objc--; break;
#endif
            
        }
        if ((enum parseOption) optionIndex == o_LAST) break;
    }

    if (feedbackAfter && !feedbackCmd) {
        if (!Tcl_GetCommandInfo(interp, "::dom::domParseFeedback", 
6567
6568
6569
6570
6571
6572
6573



6574
6575
6576
6577
6578
6579
6580
                          feedbackAfter,
                          feedbackCmd,
                          chan,
                          baseURI,
                          extResolver,
                          useForeignDTD,
                          paramEntityParsing,



                          interp,
                          &status);
    if (doc == NULL) {
        char s[50];
        long byteIndex, i;
        
        switch (status) {







>
>
>







6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
                          feedbackAfter,
                          feedbackCmd,
                          chan,
                          baseURI,
                          extResolver,
                          useForeignDTD,
                          paramEntityParsing,
#ifndef TDOM_NO_DTD_VALIDATION
                          dtdvalidation,
#endif
                          interp,
                          &status);
    if (doc == NULL) {
        char s[50];
        long byteIndex, i;
        
        switch (status) {
6658
6659
6660
6661
6662
6663
6664
6665

6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
    int featureIndex, result;
    
    static const char *features[] = {
        "expatversion",      "expatmajorversion",  "expatminorversion",
        "expatmicroversion", "dtd",                "ns",
        "unknown",           "tdomalloc",          "lessns",
        "html5",             "jsonmaxnesting",     "versionhash",
        "pullparser",        "TCL_UTF_MAX",        NULL

    };
    enum feature {
        o_expatversion,      o_expatmajorversion,  o_expatminorversion,
        o_expatmicroversion, o_dtd,                o_ns,
        o_unknown,           o_tdomalloc,          o_lessns,
        o_html5,             o_jsonmaxnesting,     o_versionhash,
        o_pullparser,        o_TCL_UTF_MAX,
    };

    if (Tcl_GetIndexFromObj(interp, objv[1], features, "feature", 0,
                            &featureIndex) != TCL_OK) {
        return TCL_ERROR;
    }








|
>






|







6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
    int featureIndex, result;
    
    static const char *features[] = {
        "expatversion",      "expatmajorversion",  "expatminorversion",
        "expatmicroversion", "dtd",                "ns",
        "unknown",           "tdomalloc",          "lessns",
        "html5",             "jsonmaxnesting",     "versionhash",
        "pullparser",        "TCL_UTF_MAX",        "dtdvalidation",
        NULL
    };
    enum feature {
        o_expatversion,      o_expatmajorversion,  o_expatminorversion,
        o_expatmicroversion, o_dtd,                o_ns,
        o_unknown,           o_tdomalloc,          o_lessns,
        o_html5,             o_jsonmaxnesting,     o_versionhash,
        o_pullparser,        o_TCL_UTF_MAX,        o_dtdvalidation
    };

    if (Tcl_GetIndexFromObj(interp, objv[1], features, "feature", 0,
                            &featureIndex) != TCL_OK) {
        return TCL_ERROR;
    }

6752
6753
6754
6755
6756
6757
6758








6759
6760
6761
6762
6763
6764
6765
        result = 0;
#endif
        SetBooleanResult(result);
        break;
    case o_TCL_UTF_MAX:
        SetIntResult(TCL_UTF_MAX);
        break;








    }
    return TCL_OK;
}

/*----------------------------------------------------------------------------
|   tcldom_DomObjCmd
|







>
>
>
>
>
>
>
>







6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
        result = 0;
#endif
        SetBooleanResult(result);
        break;
    case o_TCL_UTF_MAX:
        SetIntResult(TCL_UTF_MAX);
        break;
    case o_dtdvalidation:
#ifndef TDOM_NO_DTD_VALIDATION
        result = 1;
#else
        result = 0;
#endif
        SetBooleanResult(result);
        break;
    }
    return TCL_OK;
}

/*----------------------------------------------------------------------------
|   tcldom_DomObjCmd
|

Changes to tdom.m4.

261
262
263
264
265
266
267









































268
269
270
271
272
273
274
        else
            AC_MSG_ERROR([The required lib gumbo not found])
        fi
    else    
        AC_MSG_RESULT([no])
    fi
])










































#------------------------------------------------------------------------
# TDOM_PATH_AOLSERVER
#
#   Allows the building with support for AOLserver 
#
# Arguments:







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







261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
        else
            AC_MSG_ERROR([The required lib gumbo not found])
        fi
    else    
        AC_MSG_RESULT([no])
    fi
])

#------------------------------------------------------------------------
# TDOM_ENABLE_DTD_VALIDATION --
#
#   Building with validation features.
#
# Arguments:
#   None
#   
# Results:
#
#   Adds the following arguments to configure:
#       --enable-dtdvalidation=yes|no
#
#   Defines the following vars:
#
#   Sets the following vars:
#
#------------------------------------------------------------------------

AC_DEFUN(TDOM_ENABLE_DTD_VALIDATION, [
    AC_MSG_CHECKING([whether to enable dtd valiation])
    AC_ARG_ENABLE(dtdvalidation,
        AC_HELP_STRING([--enable-dtdvalidation],
            [build with valiation features (default: on)]),
        [tcl_ok=$enableval], [tcl_ok=yes])

    if test "${enable_dtdvalidation+set}" = set; then
        enableval="$enable_dtdvalidation"
        tcl_ok=$enableval
    else
        tcl_ok=yes
    fi

    if test "$tcl_ok" = "no" ; then
        AC_MSG_RESULT([no])
        AC_DEFINE(TDOM_NO_DTD_VALIDATION)
    else
        AC_MSG_RESULT([yes])
    fi
])

#------------------------------------------------------------------------
# TDOM_PATH_AOLSERVER
#
#   Allows the building with support for AOLserver 
#
# Arguments:

Changes to tests/data/REC-xslt-19991116.xml.

6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
allowed for node-sets;</p></item>

<item><p>a way to group together consecutive nodes having duplicate
subelements or attributes;</p></item>

<item><p>features to make handling of the HTML <code>style</code>
attribute more convenient.</p></item>

</ulist>

<item><p>features to make handling of the HTML <code>style</code>
attribute more convenient.</p></item>

</inform-div1>

</back>
</spec>







<


<
<
<




6350
6351
6352
6353
6354
6355
6356

6357
6358



6359
6360
6361
6362
allowed for node-sets;</p></item>

<item><p>a way to group together consecutive nodes having duplicate
subelements or attributes;</p></item>

<item><p>features to make handling of the HTML <code>style</code>
attribute more convenient.</p></item>

</ulist>




</inform-div1>

</back>
</spec>

Changes to tests/dom.test.

15
16
17
18
19
20
21


22
23
24
25
26
27
28
#    dom-10.*: createNodeCmd
#    dom-11.*: featureinfo
#    dom-12.*: -feedbackAfter
#
# Copyright (c) 2002, 2003, 2004 Rolf Ade.

source [file join [file dir [info script]] loadtdom.tcl]



test dom-1.1 {createDocument with root node name not a XML Name} {
    list [catch {dom createDocument "root node"} msg] $msg
} "1 {Invalid root element name 'root node'}"

test dom-1.2 {createDocument with root node name not a XML Name} {
    list [catch {dom createDocument "1root"} msg] $msg







>
>







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#    dom-10.*: createNodeCmd
#    dom-11.*: featureinfo
#    dom-12.*: -feedbackAfter
#
# Copyright (c) 2002, 2003, 2004 Rolf Ade.

source [file join [file dir [info script]] loadtdom.tcl]

testConstraint dtdvalidation [dom featureinfo dtdvalidation]

test dom-1.1 {createDocument with root node name not a XML Name} {
    list [catch {dom createDocument "root node"} msg] $msg
} "1 {Invalid root element name 'root node'}"

test dom-1.2 {createDocument with root node name not a XML Name} {
    list [catch {dom createDocument "1root"} msg] $msg
668
669
670
671
672
673
674
















675


















676
677
678
679
680
















681
682
683
684
685
686
687
test dom-2.41 {-keepCDATA and -keepEmpties} {
    set doc [dom parse -keepCDATA -keepEmpties {<doc><e><![CDATA[]]></e></doc>}]
    set result [$doc selectNodes count(doc/e/node())]
    $doc delete
    set result
} 1

















test dom-2.42 {namespaces} {


















    set doc [dom parse {
        <help><br xmlns:xsi="a"/><em xmlns:xsi="a">notes</em></help>
    }]
    $doc delete
} {}

















test dom-3.1 {isName} {
    dom isName ":foo"
} {1}

test dom-3.2 {isName} {
    dom isName "_foo"







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





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







670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
test dom-2.41 {-keepCDATA and -keepEmpties} {
    set doc [dom parse -keepCDATA -keepEmpties {<doc><e><![CDATA[]]></e></doc>}]
    set result [$doc selectNodes count(doc/e/node())]
    $doc delete
    set result
} 1

proc dom-2.42-resolver {base systemId publicId} {
    switch $publicId {
        "-//W3C//DTD Specification V2.0//EN" {
            set fd [open [file join [file dir [info script]] \
                              data/xmlspec-v20.dtd]]
            set xmlspec [read $fd]
            close $fd
            return [list "string" "" $xmlspec]
        }
        default {
            puts stderr "Unexpected systemId '$systemId'"
            return ""
        }
    }
}

test dom-2.42 {-dtdvalidation} {dtdvalidation} {
    set file [file join [file dir [info script]] data/REC-xslt-19991116.xml]
    set fd [open $file]
    set doc [dom parse -dtdvalidation \
                 -channel $fd \
                 -baseurl file://$file \
                 -externalentitycommand dom-2.42-resolver]
    $doc delete
} {}

test dom-2.43 {-dtdvalidation / invalid dtd} {dtdvalidation} {
    set result [catch {
        dom parse -dtdvalidation {<!DOCTYPE root [
            <!ELEMENT root (#PCDATA|a|b|a)*>]>
            <root/>}} errMsg]
    set result
} 1

test dom-2.44 {namespaces} {
    set doc [dom parse {
        <help><br xmlns:xsi="a"/><em xmlns:xsi="a">notes</em></help>
    }]
    $doc delete
} {}

test dom-2.45 {-dtdvalidation / no dtd} {dtdvalidation} {
    set result [catch {
        #dom parse -dtdvalidation <root><e/></root>
        dom parse -dtdvalidation <root/>
    } errMsg]
    set result
} 1

test dom-2.46 {Unknown empty element} {dtdvalidation} {
    set result [catch {
        dom parse -dtdvalidation {<!DOCTYPE root [
            <!ELEMENT root (a*)>]>
            <root><b/></root>}} errMsg]
    set result
} 1

test dom-3.1 {isName} {
    dom isName ":foo"
} {1}

test dom-3.2 {isName} {
    dom isName "_foo"