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

Overview
Comment:Minor documentation and test suite work.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | schema
Files: files | file ages | folders
SHA3-256: a14c1bb5159ae86a7c3b0636b8abfc7fd3cdad74c41d31e55cdb9ecbefff373b
User & Date: rolf 2020-07-31 10:59:44
Context
2020-08-01
23:33
Added text constraint command length. check-in: cc382337fc user: rolf tags: schema
2020-07-31
10:59
Minor documentation and test suite work. check-in: a14c1bb515 user: rolf tags: schema
2020-07-30
14:33
Integrated further improvements and features to recovering. check-in: 0e98933aa6 user: rolf tags: schema
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to doc/schema.xml.

204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
...
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
....
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
        <m>objVar</m> argument is given, then the variable with that
        name is set to a validation error message. If the dom tree is
        valid and the optional <m>objVar</m> argument is given, then
        the variable with that name is set to the empty string. </desc>
      </commanddef>

      <commanddef>
        <command><method>reportcmd</method> <m>?cmdName?</m></command>
        <desc>This method expects the name of a tcl command to be
        called in case of validation error. This command will be
        called with two arguments: the schema command, that is rasing
        the validation error, and a validation error code. For more
        detailed information see <ref
        refid="recovering">Recovering</ref>.The possible error codes
        are:
        <dl>
            <dt>MISSING_ELEMENT</dt><dd></dd>
            <dt>MISSING_TEXT</dt><dd></dd>
            <dt>UNEXPECTED_ELEMENT</dt><dd></dd>
            <dt>UNEXPECTED_ROOT_ELEMENT</dt><dd></dd>
................................................................................
                  meanings are:</p>
                  <dl>
                      <dt>NONE</dt><dd>The schema command currently
                      doesn't recover from a validation event.</dd>
                      <dt>MATCH_ELEMENT_START</dt><dd>Element start event, which includs looking for missing or unknown attributes.</dd>
                      <dt>MATCH_ELEMENT_END</dt><dd>Element end event.</dd>
                      <dt>MATCH_TEXT</dt><dd>Validating text between tags.</dd>
                      <dt>MATCH_ATTRIBUTE_TEXT</dt><dd>Attribute text value contraint check</dd>
                      <dt>MATCH_GLOBAL</dt><dd>Checking global IDs</dd>
                      <dt>MATCH_DOM_KEYCONSTRAINT</dt><dd>Checking domunique constaint</dd>
                      <dt>MATCH_DOM_XPATH_BOOLEAN</dt><dd>Checking domxpathboolean constaint</dd>
                  </dl>
                  If called with one of the possible optional
                  arguments the command returns detail information
                  depending on current action.
................................................................................
    
  </section>

  <section id="recovering">
      <title>Recovering</title>

      <p>By default the validation engine stops at the first detected
      validation violation and reports that finding. It does so by
      result false (and set, if given, the result variable with an
      error message) in case the schema command itself is used to
      validate input. If the schema command is used by a SAX parser or
      the DOM parser it does so by throwing error.</p>

      <p>If a <m>reportcmd</m> is set this command is called on global
      level appended with the schema command and an error type as
      arguments if a validation violation is detected. Then the







|


|
|
|







 







|







 







|
|







204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
...
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
....
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
        <m>objVar</m> argument is given, then the variable with that
        name is set to a validation error message. If the dom tree is
        valid and the optional <m>objVar</m> argument is given, then
        the variable with that name is set to the empty string. </desc>
      </commanddef>

      <commanddef>
        <command><method>reportcmd</method> <m>?cmd?</m></command>
        <desc>This method expects the name of a tcl command to be
        called in case of validation error. This command will be
        called with two arguments appended: the schema command, that
        is rasing the validation error, and a validation error code.
        For more detailed information see <ref
        refid="recovering">Recovering</ref>.The possible error codes
        are:
        <dl>
            <dt>MISSING_ELEMENT</dt><dd></dd>
            <dt>MISSING_TEXT</dt><dd></dd>
            <dt>UNEXPECTED_ELEMENT</dt><dd></dd>
            <dt>UNEXPECTED_ROOT_ELEMENT</dt><dd></dd>
................................................................................
                  meanings are:</p>
                  <dl>
                      <dt>NONE</dt><dd>The schema command currently
                      doesn't recover from a validation event.</dd>
                      <dt>MATCH_ELEMENT_START</dt><dd>Element start event, which includs looking for missing or unknown attributes.</dd>
                      <dt>MATCH_ELEMENT_END</dt><dd>Element end event.</dd>
                      <dt>MATCH_TEXT</dt><dd>Validating text between tags.</dd>
                      <dt>MATCH_ATTRIBUTE_TEXT</dt><dd>Attribute text value constraint check</dd>
                      <dt>MATCH_GLOBAL</dt><dd>Checking global IDs</dd>
                      <dt>MATCH_DOM_KEYCONSTRAINT</dt><dd>Checking domunique constaint</dd>
                      <dt>MATCH_DOM_XPATH_BOOLEAN</dt><dd>Checking domxpathboolean constaint</dd>
                  </dl>
                  If called with one of the possible optional
                  arguments the command returns detail information
                  depending on current action.
................................................................................
    
  </section>

  <section id="recovering">
      <title>Recovering</title>

      <p>By default the validation engine stops at the first detected
      validation violation and report that finding. It does so by
      return false (and set, if given, the result variable with an
      error message) in case the schema command itself is used to
      validate input. If the schema command is used by a SAX parser or
      the DOM parser it does so by throwing error.</p>

      <p>If a <m>reportcmd</m> is set this command is called on global
      level appended with the schema command and an error type as
      arguments if a validation violation is detected. Then the

Changes to tests/schema.test.

2397
2398
2399
2400
2401
2402
2403
























2404
2405
2406
2407
2408
2409
2410
....
8222
8223
8224
8225
8226
8227
8228































8229
8230
8231
8232
8233
8234
8235
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 0 1 1 1 1 1 1 1 0}

























test schema-8.1 {validate method} {
    tdom::schema create grammar
    grammar defelement doc {
        element e1
        element e2 *
    }
    foreach e {e1 e2} {
................................................................................
        lappend result {*}$fromReportCmd
        incr xmlnr
    }
    s delete
    set result
} {0: 1 {END_EVENT doc} {expecting a} {END_EVENT doc} {expecting b} {END_EVENT doc} {expecting c} {END_EVENT doc} {expecting d} 1: 1 {END_EVENT doc} {expecting b} {END_EVENT doc} {expecting c} {END_EVENT doc} {expecting d} 2: 1 {END_EVENT doc} {expecting c} {END_EVENT doc} {expecting d} 3: 1 {MATCH_ELEMENT_START expecting c} 4: 1 5: 1 {MATCH_ELEMENT_START expecting d}}
































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







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







 







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







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
....
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 0 1 1 1 1 1 1 1 0}

test schema-7.22 {Constraint text content in seq} {
    tdom::schema s
    s defelement doc {
        element a
        text {
            minLength 4
        }
        element b
    }
    set result [list]
    foreach xml {
        <doc/>
        <doc><a/>1234<b/></doc>
        <doc><a/>123<b/></doc>
        <doc><a/>12345<b/></doc>
        {<doc><a/>    <b/></doc>}
        {<doc>  <a/>    <b/></doc>}
    } {
        lappend result [s validate $xml]
    }
    s delete
    set result
} {0 1 0 1 1 1}
        
test schema-8.1 {validate method} {
    tdom::schema create grammar
    grammar defelement doc {
        element e1
        element e2 *
    }
    foreach e {e1 e2} {
................................................................................
        lappend result {*}$fromReportCmd
        incr xmlnr
    }
    s delete
    set result
} {0: 1 {END_EVENT doc} {expecting a} {END_EVENT doc} {expecting b} {END_EVENT doc} {expecting c} {END_EVENT doc} {expecting d} 1: 1 {END_EVENT doc} {expecting b} {END_EVENT doc} {expecting c} {END_EVENT doc} {expecting d} 2: 1 {END_EVENT doc} {expecting c} {END_EVENT doc} {expecting d} 3: 1 {MATCH_ELEMENT_START expecting c} 4: 1 5: 1 {MATCH_ELEMENT_START expecting d}}

proc schema-17.28 {userarg scmd errType} {
    append ::result $userarg $scmd $errType
}

test schema-17.28 {reportcmd with additional args} {
    tdom::schema s
    s defelement doc {
        element a
    }
    s reportcmd "schema-17.28 foo"
    set result ""
    s validate <doc><wrong/></doc
    s delete
    set result
} foosMISSING_ELEMENT

proc schema-17.29 {args} {
    error "triggered"
}

test schema-17.29 {error in reportcmd} {
    tdom::schema s
    s defelement doc {
        element a
    }
    s reportcmd schema-17.29
    set result [catch {s validate <doc><wrong/></doc} errMsg]
    s delete
    append result $errMsg
} {1error "triggered" at line 1 character 13}

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